繁体   English   中英

Eclipse,tomcat,404错误

[英]Eclipse, tomcat, 404 error

我正在学习servlet并遵循教程(我一步一步地遵循,但我将项目命名为“SampleServlet”而不是“de.vogella.wtp.filecounter”)。 当我启动服务器(步骤5.4)时,我收到404页面错误:

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.

从哪里开始调试? 服务器启动时,控制台中有几个“INFO”,一个警告:

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.

我需要更改任何偏好吗?

本教程建议您通过http:// localhost:8080 / de.vogella.wtp.filecounter / FileCounter调用它。 项目名称默认为上下文名称de.vogella.wtp.filecounter ,您已将其更改为SampleServlet ,因此需要通过http:// localhost:8080 / SampleServlet / FileCounter调用servlet。

也可以看看:


至于SetPropertiesRule警告,只需忽略它,这是正常的。 Eclipse只是为Tomcat的<Context>元素添加了一个额外的属性,以便能够将已部署的webapp与特定项目相关联。 Tomcat只是抽搐,因为它不会将其识别为预定义的<Context>属性之一。 然而,它试图帮助最终用户实际上输入错误的情况等等。 只是忽略它。 导出Web应用程序并将其部署到实际生产服务器上时,您将看不到它。

好的,根据你的web.xml,你似乎错过了一个servlet定义和一个servlet-mapping。 我不知道为什么这不是由你的ide产生的。 它应该是这样的:

<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>

servlet-mapping元素中,您只需将任何url映射到上面定义的servlet。 因此,如果您现在调用http:// yourserver:8080 / projectname / mysample将调用Servlet your.package.SampleServlet。

我希望有所帮助。

将FileCounter添加为web.xml中的欢迎文件之一,如下所示。

<?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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM