Bookmark Topic Watch Topic
  • New Topic

Run Servlet without registering it in web.xml

 
Jay Shukla
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Report post to moderator
I have following folder structure in my apache-tomcat 6.0.16/webapps.

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

I came to know that you can run your Servlet without even register it (by making an entry in web.xml).
So tried to run it by giving following URL in my browser.

http://localhost/webapps/servlet/Ch01.src.FirstServlet

By it gave my HTTP Status 404 code webapps/servlet/Ch01.src.FirstServlet.
Can anyone please advice me what could be done to resolve this.

Thanks in Advance.
 
Jay Shukla
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi Sorry the Folder Structure is not displayed correctly. its as follows.

 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Report post to moderator
I know what it's not working, but you really shouldn't do that. Mapping the servlet properly in the web.xml has many advantages over this Tomcat-specific technique. For more detail see http://faq.javaranch.com/java/InvokerServlet
 
Jay Shukla
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Report post to moderator
Thanks for reply Ulf.

Yes actaully i was readiing about servlet in a book (Servlet & JSP Cookbook - O'reilly) so i though of just trying.

I checked in my apache-tomcat-6.0.16\conf\web.xml entry its as follows.



Hence i made changes (commented servlet related tages) in my application specific web.xml (File in my context root

web.xml (my application specific)
======




Please advice if i am doing any wrong here.

Thanks in Advance.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Report post to moderator


ALL classes used in servlets should be in packages and stored in the package directory under classes.

The reason being that when the JVM sees a class in the "default" package, it looks in the "current directory" - you have no control over the current directory in a servlet.

The early servlet API architects thought they were doing us a favor by creating the "invoker" servlet which could pass on a request to a unregistered servlet in the default package.

This has caused incredible confusion and frustration. See the link Ulf cited for the full story.

Bill
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65528
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
You've now spread "how to run a servlet" over three topics. Let's keep it to one.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!