views:

868

answers:

4

What culprits are the most likely to cause a 404 resource not found error when a page in a given .WAR, autocreated by Sun's J2EE deploytool, is trying to load a Servlet in the same .WAR file?
Eg:

HTTP Status 404 - /MyServlet/MyServlet

type Status report

message /MyServlet/MyServlet

description The requested resource (/MyServlet/MyServlet) is not available.


Related: Of these, how many would you expect to be server specific? eg: Sun Java Application Server vs Tomcat & Catalina ?

+3  A: 

Is there a valid <servlet-mapping> for 'MyServlet' in your web.xml? That's been my number one culprit in the past

pkaeding
A: 

A 404 error means that the requested resource was not found. As pkaeding suggests, it is probably due to the servlet mapping not being correct (or not being present) in the web.xml file. Servlets must be specified in the web.xml file, and not only that, but they must be mapped to particular paths (an "url-mapping"). If the "MyServlet" servlet exists, but is not mapped to a path that may resolve with "/MyServlet/MyServlet" based on the application context root, and nothing else (i.e. another servlet, etc) resolves with this path, the application server will throw a 404 stating that nothing is mapped to the given path.

MetroidFan2002
A: 

I just spent about an hour pulling my hair out on this very problem. Tomcat 5.5.27 on OSX was working just fine until I'd added another servlet and servlet-mapping at which point everything was returning a 404. I hadn't realized it, but when I'd added a new servlet/servlet-mapping pair I'd put the servlet-mapping before the servlet entry. It's an easy mistake to make and, although knee-capping the entire application without giving anything resembling a sensible error message seems a little extreme, it makes perfect sense in retrospect.

RG
A: 

Servlet mapping is a common problem. But if you have any fitlers in your web.xml those can be the culprit as well. One thing to realize is filters always execute the code before the doFilter before any servlets starts executing. (Technically filters execute code after the doFilter) In our code we created filters that would return 404 under certain situations. Sometimes removing some or all filters-mapping will help discover if it is related to filter-mappings.

JeffJak