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?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With