2013-06-21 105 views
3

在過去的幾個小時裏,我一直在關注這個問題。這是我第一次嘗試編寫Web應用程序並將其部署到apache tomcat Web容器。我遵循here的簡單教程,然後得到這個錯誤。嘗試了一些解決方案,如其他帖子中關於同一問題的內容,但目前爲止似乎沒有任何解決方案。我正在分別粘貼和web.xml,website.xml和我的代碼文件的片段。請看看我是否做錯了什麼。提前致謝。我該如何擺脫:HTTP狀態405 - 此方法不支持HTTP方法GET?

web.xml中:

<?xml version="1.0"?> 
<web-app 
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
     http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" 
    version="2.4"> 
    <servlet> 
     <servlet-name>home</servlet-name> 
     <servlet-class>website.web.TestServlet</servlet-class> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>home</servlet-name> 
     <url-pattern>/home</url-pattern> 
    </servlet-mapping> 
</web-app> 

website.xml:

<Context path="/website" docBase="C:\Users\Priyankar\workspace\website\web" /> 

HomeServlet.java

package website.web; 

import java.io.IOException; 
import java.io.PrintWriter; 
import javax.servlet.ServletException; 
import javax.servlet.ServletRequest; 
import javax.servlet.ServletResponse; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 

public class HomeServlet extends HttpServlet { 

    @Override 
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
       throws ServletException, IOException { 
        PrintWriter writer = resp.getWriter(); 
        writer.println("<h1>Hello, World!</h1>"); 
       }   
} 

下面是什麼我看到localhost_access_log

0:0:0:0:0:0:0:1 - admin [21/Jun/2013:13:25:40 -0500] "POST /manager/html/deploy?org.apache.catalina.filters.CSRF_NONCE=435C56002971030D163AA1C798F91722 HTTP/1.1" 200 14076 
0:0:0:0:0:0:0:1 - - [21/Jun/2013:13:28:50 -0500] "GET /website/home HTTP/1.1" 405 1065 

manager_log

Jun 21, 2013 1:25:40 PM org.apache.catalina.core.ApplicationContext log 
INFO: HTMLManager: init: Associated with Deployer 'Catalina:type=Deployer,host=localhost' 
Jun 21, 2013 1:25:40 PM org.apache.catalina.core.ApplicationContext log 
INFO: HTMLManager: init: Global resources are available 
Jun 21, 2013 1:25:40 PM org.apache.catalina.core.ApplicationContext log 
INFO: HTMLManager: install: Installing context configuration at 'C:\Users\Priyankar\workspace\website\website.xml' 
Jun 21, 2013 1:25:40 PM org.apache.catalina.core.ApplicationContext log 
INFO: HTMLManager: list: Listing contexts for virtual host 'localhost' 

其餘的看似平常的我,除非你想看看在任何特定的日誌文件。

錯誤消息:

HTTP Status 500 - Error instantiating servlet class website.web.TestServlet 

type Exception report 

message Error instantiating servlet class website.web.TestServlet 

description The server encountered an internal error that prevented it from fulfilling this request. 

exception 

javax.servlet.ServletException: Error instantiating servlet class website.web.TestServlet 
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) 
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) 
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) 
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) 
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023) 
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) 
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) 
    java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
    java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    java.lang.Thread.run(Unknown Source) 

root cause 

java.lang.ClassNotFoundException: website.web.TestServlet 
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714) 
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559) 
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) 
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) 
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) 
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) 
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023) 
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) 
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) 
    java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
    java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    java.lang.Thread.run(Unknown Source) 

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.41 logs. 
Apache Tomcat/7.0.41 

下面是從Package Explorer中的項目樹的屏幕截圖:

enter image description here

+0

發佈您正在進行此GET請求的部分。 –

+0

我想我會希望看到作家被關閉.... – DaveH

+0

localhost:8080 /網站/家 – user25104

回答

2

在你的屏幕截圖中的代碼是一個名爲website.web.TestServlet一個Java類但您的web.xml和代碼發佈說website.web.HomeServlet

+0

您好我已經改名爲TestServlet在web.xml文件,但忘了編輯它在這裏。現在編輯xml文件以反映更改。 – user25104

2

你給的類名是TestServlet,你的web.xml是HomeServlet。所以當你點擊URL時,找不到任何名爲HomeServlet的東西。

稍微偏離主題,但相關:你會部署過程本身,如果你有

<load-on-startup>0</load-on-startup> 

標籤抓住了這個。

這基本上在部署期間加載Servlet,如果它沒有找到任何它會拋出。如果你不給這個標籤,服務器只要感覺就加載。

+0

謝謝。現在就試試吧。 – user25104

+0

編輯了實際的xml文件,當我部署Web應用程序時,它說TestServlet不是HomeServlet。它只是忘了在這裏編輯它。抱歉。 – user25104

相關問題