Results 1 to 4 of 4
  1. #1
    shuklajayb is offline Member
    Join Date
    Nov 2007
    Posts
    3
    Rep Power
    0

    Default HTTP 404 Error while running Servlet Application

    Hi I'm getting HTTP 404 error code while running a Servlet Application.

    folder structure is as follows

    apache-tomcat-6.0.16
    |--webapps
    |--Ch01
    |--WEB-INF
    |--src
    |--com
    |--FirstServlet.java
    |--classes
    |--com
    |FirstServlet.class


    web.xml is as followos:

    web.xml
    =======

    <servlet>
    <servlet-name>FirstServlet</servlet-name>
    <servlet-class>com.FirstServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>FirstServlet</servlet-name>
    <url-pattern>/firstservlet</url-pattern>
    </servlet-mapping>.

    Please Help me in resolving this.

    Thanks in Advance.

  2. #2
    devin is offline Member
    Join Date
    Feb 2009
    Posts
    13
    Rep Power
    0

    Default

    I remember when I first started working with servlets and tomcat and I was getting 404 errors but I can't remember why.

    I tried your servlet mapping and it worked on my version of tomcat, but I am using tomcat5.5. Not sure if something changed with the version you are using.

    What is the content of the servlet?

    Any errors when you reload the webapp?

    Here is the content of the servlet I tried:

    package com;

    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;

    /**
    * This is a test servlet
    *
    */

    public class FirstServlet extends HttpServlet {


    @Override public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {

    response.setContentType("text/html");

    PrintWriter out = response.getWriter();

    String docType = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
    "Transitional//EN\">\n";

    String title = "First Servlet";
    out.println
    (docType +
    "<html>\n" +
    "<head><title>" + title + "</title></head>\n" +
    "<body BGCOLOR=\"#FDF5E6\">\n" +
    "<h2>" + title + "</h2>\n" +
    "Hey this is the first servlet!"+
    "</body></html>");
    }

    @Override public void doPost(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {
    doGet(request, response);
    }


    }

  3. #3
    Join Date
    Apr 2009
    Posts
    9
    Rep Power
    0

    Default

    The servlet code looks correct. What is the link that you are hitting when you get the 404 error?

    (The URL is case sensitive - just check if you are hitting the right URL)

  4. #4
    devin is offline Member
    Join Date
    Feb 2009
    Posts
    13
    Rep Power
    0

    Default

    This could also be a security issue. Do any pages work for the Site?

    Try setting security to no in your tomcat start up script:
    TOMCAT5_SECURITY=no


    You shouldn't do this for production systems but makes things easier when just trying to learn stuff.

Similar Threads

  1. Problem in running jasper report in servlet
    By khadaree in forum Java Servlet
    Replies: 1
    Last Post: 07-16-2009, 10:35 AM
  2. Run servlet in HTTP server
    By jithan in forum New To Java
    Replies: 25
    Last Post: 10-16-2008, 11:10 AM
  3. HTTP Status 404 - Servlet action is not available---Error
    By sireesha in forum Web Frameworks
    Replies: 0
    Last Post: 04-18-2008, 08:25 PM
  4. HTTP Status 404 - Servlet action is not available
    By onceuponatime in forum Java Servlet
    Replies: 1
    Last Post: 12-11-2007, 05:29 PM
  5. Doubt in running the servlet
    By ramachandran in forum Java Servlet
    Replies: 0
    Last Post: 10-25-2007, 08:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •