File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

404 when trying to access servlet

 
Christopher De Castro
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Christopher De Castro
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you intend to address index.jsp directly, it cannot be under the WEB-INF folder.
 
Samrat Gadamsetty
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic