hi everyone..im 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 HelloServlet.java
import java.io.*;
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();
response.setContentType("text/html");
String name=request.getParameter("name");
//PrintWriter out = response.getWriter();
String doctype ="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
"Transitional//EN\">\n";
// response.setContentType("text/html");
out.println(doctype+"<html><body>");
out.println("<H3>");
out.println("hello"+name);
out.println("</html></html>");
out.close();
}
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">
<HTML>
<BODY>
<FORM ACTION="/test/HelloServlet" METHOD="post">
entername
<INPUT TYPE="TEXT" NAME = "name">
<INPUT TYPE="submit" value="SUBMIT ORDER">
</FORM>
</BODY>
</HTML>
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
http://localhost:8080/test/my.html it does display my html page but wen i enter the text and click on submit i get the following error..
http://localhost:8080/test/HelloServlet 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