Hi all,

I am writing my first servlet, and facing some troubles.

I have my servlet:

package com.example.servlet;
// other imports...
public class Hello extends HttpServlet{
	public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
		res.setContentType("text/html");
		PrintWriter out = res.getWriter();
		
		String name = req.getParameter("name");
		out.println("<HTML>");
		out.println("<HEAD><TITLE>Hello, " + name + "</TITLE></HEAD>" );
		out.println("<BODY>");
		out.println("Hello, " + name);
		out.println("</BODY></HTML>");
	}
}

I have modified my web.xml file as follow:

<servlet>
	<servlet-name>hello1</servlet-name>
	<servlet-class>com.example.servlet.Hello</servlet-class>
</servlet>
<servlet-mapping>
	<servlet-name>hello1</servlet-name>
	<url-pattern>/hello1/*</url-pattern>
</servlet-mapping>

I have my HTML page: I am not sure if the path that I have provided for ACTION is correct... should it be relative to which directory???

<HTML>
<HEAD>
<TITLE>Just say hello</TITLE>
</HEAD>
<BODY>
<FORM METHOD=GET ACTION="com\example\servlet\Hello">   // is this path correct???
What's your name?
<INPUT TYPE=TEXT NAME="name"><P>
<INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>

My folder structure for tomcat is:

C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\

Hello.java - C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\mySite\WEB-INF\classes\com\example\servlet\
index.html - C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\mySite\
web.xml - C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\mySite\WEB-INF\

The error that I am getting is "HTTP Status 404" and complaining that servlet page doesn't exist.

Please advise...


Thanks in advance

it should be /hello1 as that's the mapping you've created in your web.xml.

Thanks for reply. It worked. :-)

This question has already been answered. Start a new discussion instead.