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