• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

yet another 404 status code message

 
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<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
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot. It's really silly mistake.. I overlooked that.. now everything works fine..
 
If I had asked people what they wanted, they would have said faster horses - Ford. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic