aspose file tools*
The moose likes Servlets and the fly likes 404 when trying to access servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "404 when trying to access servlet" Watch "404 when trying to access servlet" New topic
Author

404 when trying to access servlet

Christopher De Castro
Greenhorn

Joined: Feb 11, 2011
Posts: 6
Hello, I've been trying to learn to use servlets but I've unfortunately hit a roadblock. I'm pretty sure I've defined by web.xml correctly, but I'm getting a 404 when I try to access my servlet. I can go to index.jsp just fine, but not any of the servlets that I've tried. I'm using Tomcat and Eclipse, if it matters. No errors appear in the tomcat logs.

I guess the weird thing is that this behavior seems to be inconsistent. The 404 happens when I deploy the application by creating an XML file with a docBase and a path in TOMCAT_HOME\conf\Catalina\localhost. However, when I use the Eclipse plugin to deploy the app (the plugin points to the same TOMCAT_HOME above) or if I build a war file and drop it into TOMCAT_HOME\webapps, the above behavior is reversed. I can access the servlet but not any of my static files (JSPs, HTMLs, etc.). Has anyone encountered this behavior? I've been stuck for days.



Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

The deployment descriptor looks fine, but you haven't told us anything about the folder structure of your application. It sounds like you may not have all the files in the right places.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Christopher De Castro
Greenhorn

Joined: Feb 11, 2011
Posts: 6
Thanks for the reply. My directory structure looks like this:

PROJECT_NAME
----src
----webapp
--------WEB-INF
------------classes
------------lib
---------------servlet-api.jar
------------index.jsp
------------web.xml

The servlet class is located in the classes folder as WEB-INF/classes/com/myapp/servlet/TestServlet.class
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

If you intend to address index.jsp directly, it cannot be under the WEB-INF folder.
Samrat Gadamsetty
Greenhorn

Joined: Feb 10, 2011
Posts: 29
Dear Christopher,
Follow the directory structure to run your servlet application ( I think)
place your jsp/html in web (not in web-inf)
web.xml in web-inf
servlets/java in src
Hope this works..
Correct me if anything wrong.
thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

Samrat Gadamsetty wrote:place your jsp/html in web (not in web-inf)

There is no mandate for a folder named web.

web.xml in web-inf

WEB-INF, not web-inf. Case counts.

servlets/java in src

Java sources are not part of the web application. It doesn't matter where they go and are not usually bundled with the web app.

Christopher De Castro
Greenhorn

Joined: Feb 11, 2011
Posts: 6
Thank you I knew it was going to be something silly that I couldn't figure out. I've moved out my JSPs and JS files and they're all working OK.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 404 when trying to access servlet