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{
		PrintWriter out = res.getWriter();
		String name = req.getParameter("name");
		out.println("<HEAD><TITLE>Hello, " + name + "</TITLE></HEAD>" );
		out.println("Hello, " + name);

I have modified my web.xml file as follow:


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???

<TITLE>Just say hello</TITLE>
<FORM METHOD=GET ACTION="com\example\servlet\Hello">   // is this path correct???
What's your name?

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

Recommended Answers

All 2 Replies

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

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

Thanks for reply. It worked. :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.