Eclipse, tomcat, 404 error
Solution 1
The tutorial is suggesting you to invoke it by http://localhost:8080/de.vogella.wtp.filecounter/FileCounter. The project name defaults to context name de.vogella.wtp.filecounter
which you've changed to SampleServlet
, so you need to invoke the servlet by http://localhost:8080/SampleServlet/FileCounter.
See also:
As to the SetPropertiesRule
warning, just ignore it, that's normal. Eclipse is just adding an extra attribute to Tomcat's <Context>
element to be able to associate the deployed webapp with a particular project. Tomcat is just jerking because it don't recognize it as one of the predefined <Context>
attributes. It's however trying to be helpful for the case the enduser actually made a typo and so on. Just ignore it. You won't see it when you export the webapp and deploy it on a real production server.
Solution 2
Okay according to your web.xml it seems like you're missing a servlet definition and a servlet-mapping. I Don't know why this is not generated by your ide. It should be something like this:
<servlet>
<servlet-name>SampleServlet</servlet-name>
<servlet-class>your.package.SampleServlet</servlet-class> <!-- The full qualified package path to your Servlet class -->
</servlet>
<servlet-mapping>
<servlet-name>SampleServlet</servlet-name>
<url-pattern>/mysample</url-pattern>
</servlet-mapping>
In the servlet-mapping
Element you just map any url to your servlet defined above. So if you now call http://yourserver:8080/projectname/mysample the Servlet your.package.SampleServlet will be called.
I hope that helps.
bancer
Careers profile: http://careers.stackoverflow.com/bancer Author of SprintDict for Android: http://sprintdict.bancer.net/
Updated on June 26, 2022Comments
-
bancer almost 2 years
I am learning servlets and follow this tutorial (I follow step by step but I named the project "SampleServlet" instead of "de.vogella.wtp.filecounter"). When I start the server (step 5.4) I get 404 page error:
HTTP Status 404 - /SampleServlet/servlet/de.vogella.wtp.filecounter.servlets.FileCounter type Status report message /SampleServlet/servlet/de.vogella.wtp.filecounter.servlets.FileCounter description The requested resource (/SampleServlet/servlet/de.vogella.wtp.filecounter.servlets.FileCounter) is not available.
Where to start debugging? There were several "INFO" in the console when server started and one warning:
29.08.2011 21:03:44 org.apache.tomcat.util.digester.SetPropertiesRule begin WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:SampleServlet' did not find a matching property.
Do I need to change any preferences?
-
BalusC over 12 yearsPlease note that the OP posted the
web.xml
of Tomcat itself, not of the webapp. -
bancer over 12 yearsWhen I right click on the
FileCounter.java
file in the Project Explorer tab and select "Run As"->"Run on Server" the internal browser opens localhost:8080/SampleServlet/servlet/… with 404 error. localhost:8080/SampleServlet/FileCounter results with the same error. -
bancer over 12 yearsSuper! That works! I wonder why these changes in
web.xml
file were not generated by Eclipse. -
BalusC over 12 yearsPlease note that you should not edit the
web.xml
of the server! You should edit or create the one of your webapp. -
BalusC over 12 yearsI now understand why you run into problems. That tutorial is targeted on Servlet 2.5 while you've created a Servlet 3.0 project which by default get built without
web.xml
. You would need the@WebServlet
annotation instead. Put this line@WebServlet(urlPatterns={"/FileCounter"})
on top of the servlet class declaration. And please, undo all changes you made in Tomcat's ownweb.xml
. This is not the right way to declare your own servlets, it makes your webapp unportable! -
Chris over 12 yearsYes BalusC is right! Look for the web.xml file located in your project directory under WEB-INF/web.xml.
-
boettger1 about 12 years@BalusC's answer brought me back from the brink of suicide. When creating the servlet from WebContent, simply don't overwrite the auto-generated
@WebServlet("/FileCounter")
annotation in the servlet class. What I'm still puzzled by is why Eclipse (Indigo) is not appending /FileCounter to the URL... why do we have to add it manually?