File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes help needeed.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "help needeed...." Watch "help needeed...." New topic

help needeed....

syed rizwaan

Joined: Dec 03, 2008
Posts: 2
hi a newbie to this site and new to servlets aswell..
my problem is..

how to submit a form data using html as frontend into a servlet on the apachetomcat server..

i wrote a simple servlet as shown below

file name
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloServlet extends HttpServlet
// doGet needs to overridden to handle empty data requests.
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
PrintWriter out = response.getWriter();

String name=request.getParameter("name");
//PrintWriter out = response.getWriter();
String doctype ="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +

// response.setContentType("text/html");




public void doPost(HttpServletRequest request,
HttpServletResponse response)

throws ServletException, IOException
doGet(request, response);

and the html file for this servlet is shown below:
file name my.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<FORM ACTION="/test/HelloServlet" METHOD="post">
<INPUT TYPE="submit" value="SUBMIT ORDER">
and i placed the html file in a directory called test in webapps folder of tomcat and i placed the servlet class in the class folder of webinf folder of the test directory..
but wen i run the html file on my browser as
it does display my html page but wen i enter the text and click on submit i get the following error..

HTTP Status 404 - /test/HelloServlet


type Status report

message /test/HelloServlet

description The requested resource (/test/HelloServlet) is not available.


Apache Tomcat/5.5.27
Patel Chintan
Ranch Hand

Joined: Mar 01, 2007
Posts: 80
Check for servlet mapping in web.xml.
If servlet is not geting called then may be a problem in mapping file.

Chintan Patel, SCJP1.5,
syed rizwaan

Joined: Dec 03, 2008
Posts: 2
hi there could you please tel me how to do the mapping wen i call my servlet using html or is this the proper way of calling that web.xml file on html as mentioned below
<form action ="/test/my" method= post>
where my is the name of the url mapping for my servlet

i did try this way but still i get the same error..
so could you plese write down the whole web.xml and the corrosponding html file please and do mention how to include or call it in the html file .
and my other question is
IS is must to do the mapping for my servlet can't i call my servlet just from the html file in this way
<form action ="/test/HelloServlet" method= post>
where helloservlet is the name of my servlet
your help is much appritiated
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Somehow your DD(Deployment Descriptor) web.xml should contain your servlet mapping.

Points to ponder:
1) Your servlet class (HelloServlet) should be inside the package. The use of default package is discouraged.

2) In your view(HTML/JSP) , in form tag, the value of action attribute should not start with '/'. It should be like

Because if it starts with '/' means from the root of your application. And if you trust me and don't put '/' that means relative path. But if you are stubborn than you can try something like '/YourApplicationName/test/HelloServlet'. But the better way is to keep relative path.

3)Whenever you paste any code than use CODE tag.

4) Use meaningful topic name so that other can have some idea from the heading itself.Something like "How to map Servlet in web.xml" and not like "help needed"

Update your code and tell me "Yupee Now it works"
[ December 04, 2008: Message edited by: Vishal Pandya ]

[ December 04, 2008: Message edited by: Vishal Pandya ]

[ December 04, 2008: Message edited by: Vishal Pandya ]

[ December 04, 2008: Message edited by: Vishal Pandya ]
[ December 04, 2008: Message edited by: Vishal Pandya ]
I agree. Here's the link:
subject: help needeed....
It's not a secret anymore!