File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes servlet not being called from html Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet not being called from html" Watch "servlet not being called from html" New topic
Author

servlet not being called from html

tubu Ray
Greenhorn

Joined: Apr 19, 2006
Posts: 2
hi i am using eclipse 3.2 tomcat project to call a servlet from a html page.(code follows), but it does not get the servlet.please help.

/*******HTML:********SERVLET is the name of my project/
<html>
<body>
<h3>Enter your user id and password</h3><p>
<form action = "/SERVLET/ray.servlet.RequestServlet" method = "POST">
UserId: <input type = "text" name= "userid"><br><br>
<input type = submit value ="show statement">
</form>
</body>
</html>

/****Servlet****/
package ray.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RequestServlet extends HttpServlet
{
private PrintWriter out;
private String name;

public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
out = res.getWriter();
out.println("<html><body>");
out.println("hello");
name = req.getParameter("userid");
out.println("Welcome "+name+"<br>");
}

}
/*******WEB.xml *********/
<?xml version = "1.0"?>
<web-app>
<servlet>
<servlet-name>REQ</servlet-name>
<servlet-class>ray.servlet.RequestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>REQ</servlet-name>
<url-pattern>/servlet/login.html</url-pattern>
</servlet-mapping>
</web-app>
/********************ERROR MESSAGE**************************************/

TTP Status 404 - /SERVLET/ray.servlet.RequestServlet

type Status report

message /SERVLET/ray.servlet.RequestServlet

description The requested resource (/SERVLET/ray.servlet.RequestServlet) is not available.
Sun-Java-System/Web-Services-Pack-1.4
/***********************************************/

please help
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

You don't seem to understand what servlet mapping is.
Your form action must match one of the url pattern in your web.xml.
You've got only one pattern linked to your servlet : /servlet/login.html


[My Blog]
All roads lead to JavaRanch
tubu Ray
Greenhorn

Joined: Apr 19, 2006
Posts: 2
So how do i do this
Ganesh Chinni
Greenhorn

Joined: Dec 30, 2005
Posts: 24
change ur web.xml as follows,

<url-pattern>/SERVLET/*</url-pattern>
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Match your form action (in the html file) to the appropriate url pattern.
You should add a url pattern in your web.xml.
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026

<form action = "/SERVLET/ray.servlet.RequestServlet" method = "POST">


You got problem here. Modify this to


<form action = "servlet/login.html" method = "POST">


Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
vjy chin
Ranch Hand

Joined: Feb 17, 2005
Posts: 279
Also in the servlet you have implemented only the doGet(), but in the html you are using POST method, so you have to implement doPost() also.

Hope this helps.
Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: servlet not being called from html