在過去的幾個小時裏,我一直在關注這個問題。這是我第一次嘗試編寫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中的項目樹的屏幕截圖:
發佈您正在進行此GET請求的部分。 –
我想我會希望看到作家被關閉.... – DaveH
localhost:8080 /網站/家 – user25104