Article:
  Java Web Applications
Subject:   error 404- servlet would not load
Date:   2002-11-18 12:37:46
From:   anonymous2
I just want to share this with anyone having this problem.


Despite setting the server.xml netry for the context and, having the correct directory structure, the servlet login wouldn't load and kept giving a 404 error.


I managed to get it right by setting the web.xml file this way :


<?xml version="1.0" encoding="ISO-8859-1"?>


<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">


<web-app>
<servlet>
<servlet-name>
login
</servlet-name>
<servlet-class>
com.onjava.login
</servlet-class>
<load-on-startup>
1
</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>
login
</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
</web-app>


I don't know if this makes any sense, but the node <url-pattern> did it and it works now.

Full Threads Newest First

Showing messages 1 through 6 of 6.

  • error 404- servlet would not load
    2003-07-14 04:40:52  anonymous2 [View]

    I have my project folder and i have made modification in my server.xml i have added

    context path


    in the web.xml in the webapps /web-inf folder i am doing the servlet mapping.. but it is taking the file from the root only


    <web-app>

    <display-name>Application </display-name>
    <session-timeout>30</session-timeout>

    <servlet>
    <servlet-name>LoginServlet</servlet-name>
    <servlet-class>com.project.LoginServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
    <servlet-name>LoginServlet</servlet-name>
    <url-pattern>project/servlet/*</url-pattern>
    </servlet-mapping>

    </web-app>

    what is the solution ?..plz write back soon

    vijay_shah_78@rediffmail.com
    • error 404- servlet would not load
      2005-11-17 02:41:24  Shreyas [View]

      Tomcat has following folders
      bin, common, conf, logs, server, shared, temp and webapps

      The classpath is an environment variable that tells the java compiler javac.exe where to look for class files to import or java.exe where to find class files to interpret.

      The path is an environment variable that tells the command processor where to look for executable files. e.g. *.exe, *.com and *.bat files.

      Compiling a servlet
      You require to include in your classpath
      D:\j2sdk1.4.2_03\lib\tools.jar, where j2sdk1.4.2_03 is a java installation. now you can compile servlet source file, with javac Servlet_sourcename.java

      Setting tomcat to allow servlets to run
      create your WApp folder containing web application this contains WEB-INF and folders like classes, lib and web.xml folders.

      In web.xml folder of above web application you require to include
      <servlet>
      <servlet-name>Servlet_Name</servlet-name>
      <servlet-class>Servlet_class</servlet-class>
      </servlet>
      <servlet-mapping>
      <servlet-name>Servlet_Name</servlet-name>
      <url-pattern>/Servlet_class</url-pattern>
      </servlet-mapping>

      Add following text in tomcat_instal\conf\server.xml
      before </Host> tag

      <Context path="/WApp"
      docBase="D:\tomcat\webapps\webAppln">
      </Context>

      To execute servlet on Tomcat server
      at classpath include tomcat_dir\bin
      and type at command prompt startup
      At browser
      http://localhost:8080/WApp/Servlet-class
      will give you servlet.






      • error 404- servlet would not load
        2006-01-09 03:55:43  nitinchoube [View]

        thanks u r send me the answer.i have one Login.html file on that we r accessing the servlet file to checking the uname & pass but it will give an error:http error 404 that this servlet file is not found plz.reply.
        thanks again
        regards,
        nitin
        • error 404- servlet would not load
          2007-01-28 20:34:03  arunrash [View]

          hi.. i am getting eror like The requested resource is not available
      • error 404- servlet would not load
        2006-01-09 04:16:57  nitinchoube [View]

        Add following text in tomcat_instal\conf\server.xml
        before </Host> tag

        <Context path="/WApp"
        docBase="D:\tomcat\webapps\webAppln">
        </Context>
        when i done this after that my tomcat server is not running it terminate immidetly.plz tell me.can i type that mension above or any other canges in the server.xml file.
        plz reply it is urgent.
        thanks
        regards,
        nitin
        • error 404- servlet would not load
          2006-04-27 12:24:08  codedmind [View]

          Can you please please tell me how you finally worked around it, i also followed the instructions written here but when i changed the server and run the tomcat , it is not starting and the window is closing as soon as it opens.
          I will appreciate your help...i am strugelling with trying to run a somple hello world example on tomcat for last 2 weeks...i have to finist the project but haven't yet statred...

          please reply asap..