Bookmark Topic Watch Topic
  • Mark post as helpful
  • send pies
  • Report post to moderator
If your servlet is not running, and you are getting a 404 error, here are the things to check:

  • Make sure that your servlet class is in a package other than the default. This is not optional. As of JDK 1.4, classes in the default package cannot be imported and it can cause issues with deploying the servlet. Package your servlet class! In fact, package all of your classes -- it's a good practice in general, even when not required.

  • Make sure that the servlet class is properly placed under the WEB-INF/classes hierarchy, or properly packaged in a jar file in WEB-INF/lib.

  • Make sure that the servlet is properly declared in the deployment descriptor. The full package path to the class must be used.

  • Make sure that there is a servlet mapping for the servlet in the deployment descriptor (web.xml). The name must match the servlet declaration and the path must start with a /.

  • Make sure that the URL that you are using starts with the context path of the web application, which should be followed by the servlet mapping. For example: "/context-path/servlet-path". Using page-relative addressing in an anchor tag, or as a form action, is almost guaranteed to cause issues. Even if you can get it to work, it is fragile and can break with the least little of changes.

  • The context path is the name with which you configured the web application. For Tomcat:
    • If you used a context XML file, it's the name you configured in the path attribute.
    • If you created a war file and dropped it into Tomcat's webapps folder, it's the name of the war file.
    • If you created a folder in webapps to house the application, it's the name of the folder.
    • For containers other than Tomcat, see the container's documentation.

  • The servlet-path is the path to the servlet that you specified in the mapping for the servlet in the deployment descriptor.

  • Check the logs for errors. For Tomcat, the logs are written to logs/catalina.out.

  • If using Tomcat, use the Tomcat Manager application to make sure that the context (web app) is actually running. If not, there should be an error message in the logs as to why.

  • See TypesOfPaths for information on properly creating paths to servlets in forms. (In particular look for server-relative paths.)

      Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!