Error Eclipse, tomcat, 404

I study 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 a 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 β€œINFOs” in the console when the 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 settings?

+6
source share
3 answers

The tutorial suggests calling it http: // localhost: 8080 / de.vogella.wtp.filecounter / FileCounter . The default project name is the context name de.vogella.wtp.filecounter , which you changed to SampleServlet , so you need to call the servlet http: // localhost: 8080 / SampleServlet / FileCounter .

See also:


As for the SetPropertiesRule warning, just ignore it, that's fine. Eclipse simply adds an additional attribute to the Tomcat <Context> element to be able to associate the deployed webapp with a specific project. Tomcat just twitches because it does not recognize it as one of the predefined <Context> attributes. However, in an attempt to be useful for the occasion, the end user did make a typo and so on. Just ignore it. You will not see it when exporting webapp and deploying to a real server.

+8
source

Well, according to your web.xml, it seems like you are missing a servlet definition and a servlet mapping. I do not know why this is not caused by your idea. 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 simply map any URL to your servlet as defined above. Therefore, if you now call http: // yourserver: 8080 / projectname / mysample , the Servlet your.package.SampleServlet is called.

I hope this helps.

+5
source

Add FileCounter as one of the welcome file in web.xml, it looks like below.

 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>de.vogella.wtp.filecounter</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> <!-- <welcome-file>FirstJSP.jsp</welcome-file> --> <welcome-file>FileCounter</welcome-file> </welcome-file-list> <servlet> <description></description> <display-name>FileCounter</display-name> <servlet-name>FileCounter</servlet-name> <servlet-class>de.vogella.wtp.filecounter.servlets.FileCounter</servlet-class> </servlet> <servlet-mapping> <servlet-name>FileCounter</servlet-name> <url-pattern>/FileCounter</url-pattern> </servlet-mapping> </web-app> 
0
source

Source: https://habr.com/ru/post/896185/


All Articles