• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

404 when trying to access servlet

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.



 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you intend to address index.jsp directly, it cannot be under the WEB-INF folder.
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Yes, my master! Here is the tiny ad you asked for:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic