tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shapira, Yoav" <>
Subject RE: 404 error accessing servlet in Tomcat5
Date Thu, 26 Aug 2004 19:12:59 GMT

Is your application named HelloServlet also?  If so, I suggest changing
its name to reduce confusion.  Call it "myApp" or whatever you want.

Next, correct the actual code of your servlet.  Having an empty
service() method means your servlet will do nothing.  Take out that
method completely so that the parent class' service method is used.

I also suggest putting your servlet in a package, e.g.
com.mycompany.HelloServlet.  Modify web.xml accordingly, specifically
the <servlet-class> element.

Take out the trailing slash from the url-pattern element of the
servlet-mapping.  Take out the leading slash from the /index.jsp
welcome-file.  These two changes are not strictly needed but are better

Then restart tomcat.  You should be able to access your servlet at

And if you haven't done so already, make sure to read

Yoav Shapira
Millennium Research Informatics

>-----Original Message-----
>From: Preeti Iyer []
>Sent: Thursday, August 26, 2004 3:06 PM
>Subject: 404 error accessing servlet in Tomcat5
>I have a simple webapp with 1servler. When I run my webapp in Tomcat5
>and try accessing my servlet using
>http://localhost:8080/HelloServlet/HelloServlet , I get a 404 error
>page stating --
>HTTP Status 404 - /HelloServlet/HelloServlet
>type Status report
>message /HelloServlet/HelloServlet
>description The requested resource (/HelloServlet/HelloServlet) is not
>Apache Tomcat/5.0.19
>The following is the servlet code:---
>import javax.servlet.http.*;
>import javax.servlet.ServletException;
>import javax.servlet.ServletConfig;
>import javax.servlet.ServletContext;
>public class HelloServlet extends HttpServlet
>{  private ServletConfig config;
>       public void init(ServletConfig config) throws ServletException
>       {this.config=config;}
>       public void service(HttpServletRequest req, HttpServletResponse
>throws ServletException,IOException
>       {}
>       public void doGet(HttpServletRequest req, HttpServletResponse
>throws ServletException, IOException
>       {doPost(req,res);}
>       public void doPost(HttpServletRequest req, HttpServletResponse
>throws ServletException, IOException
>       {
>               ServletContext context=getServletContext();
>               String name=context.getInitParameter("name");
>               res.setContentType("text/html");
>               PrintWriter out=res.getWriter();
>               out.println("<html><body>Hello World");
>               out.println("context parameter name: "+ name);
>               out.println("</body></html>");
>               out.close();
>       }
>The following is the web.xml---------
><?xml version="1.0" encoding="UTF-8"?>
><!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web
>Application 2.3//EN" "">
> <servlet>
>   <servlet-name>HelloServlet</servlet-name>
>   <servlet-class>HelloServlet</servlet-class>
>   <load-on-startup>1</load-on-startup>
> </servlet>
> <servlet-mapping>
>   <servlet-name>HelloServlet</servlet-name>
>   <url-pattern>/HelloServlet/</url-pattern>
> </servlet-mapping>
> <session-config>
>   <session-timeout>270</session-timeout>
> </session-config>
> <welcome-file-list>
>   <welcome-file>/index.jsp</welcome-file>
> </welcome-file-list>
>I am able to access index.jsp by using
>What do I need to do to be able to access the servlet class? Do I need
>to do some special kind of configuration in Tomcat?
>Thanks in advance for the help.
>To unsubscribe, e-mail:
>For additional commands, e-mail:

This e-mail, including any attachments, is a confidential business communication, and may
contain information that is confidential, proprietary and/or privileged.  This e-mail is intended
only for the individual(s) to whom it is addressed, and may not be saved, copied, printed,
disclosed or used by anyone else.  If you are not the(an) intended recipient, please immediately
delete this e-mail from your computer system and notify the sender.  Thank you.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message