This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Tomcat and the fly likes yet another 404 status code message Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "yet another 404 status code message" Watch "yet another 404 status code message" New topic
Author

yet another 404 status code message

Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
Hi,

I am trying out servlet example in Tomcat 5.0.27

I created a simple TestServlet servlet. Compiled and pasted the class file in <tomcathome>\webapps\ROOT\WEB-INF\classes\TestServlet.

Then I modifed the web.xml Below you can find the part of web.xml

<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>TestServlet</servlet-class>
</servlet>

<servlet>
<servlet-name>org.apache.jsp.index_jsp</servlet-name>
<servlet-class>org.apache.jsp.index_jsp</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>org.apache.jsp.index_jsp</servlet-name>
<url-pattern>/index.jsp</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>


When I tried to open the servlet
http://localhost:18080/test

I am getting 404 Status error

however if I replace url-patter of TestServlet as
<url-pattern>index.jsp</url-patter>

and try like http://localhost:18080/

I can see the TestServlet's output.

Please let me know what configuration I need to make to resolve the issue with calling the servlet directly
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5

Put your servlet in a package and ensure that the web.xml gives the package in <servlet-class> and that the location under WEB-INF\classes is correct.
ALL Java classes used in servlets or JSP should be in packages. The reason being that when the class loader sees a class name without a package, it looks in the "current" directory - which you have no control over.
Bill
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
I did couple of changes as you suggested

1. created folder "mypackage" under classes
2. modifed the java code to include the package construct
package mypackage;

3. compiled the source code (under WEB-INF\classes\mypackage)
4. Modified the web.xml as below

<?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-apps>
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>mypackage.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/TestServlet</url-pattern>
</servlet-mapping>
</web-apps>

5. Restarted the tomcat server

6. tried to access "http://localhost:18080/test/TestServlet
I am getting same http 404 status message

* "test" is the web application context

7. when I try to access JSP page I can see the results. It's just the servlet I am facing the problem.

Please help!
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
When I move the sample servlet to ROOT context I see the output.

I guess there is something on setting the context in tomcat 5.x

I don't see the test.xml context file in conf\Catalina\localhost\ folder

Please let me know how to get the context of the web application to be generated...
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

<web-apps>
should be
<web-app>

That probably prevents your context from starting successfully, which probably is also why you don't find your context xml file, and certainly why you get a 404.

Also, you're changing the web.xml file under your app's WEB-INF/lib, and not the one in tomcat's conf directory, right?
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
Thanks a lot. It's really silly mistake.. I overlooked that.. now everything works fine..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: yet another 404 status code message