2015-09-21 134 views
0

這是我使用的代碼:從形式調用servlet不是工作

public class MyServlet extends HttpServlet { 
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
     // whatever I need to do 
    } 
} 

JSP

<form action="/myServlet" method="post"> 
    <input type="submit" value="Submit"> 
</form> 

web.xml

<servlet> 
    <servlet-name>myServlet</servlet-name> 
    <servlet-class>com.myPackage.MyServlet</servlet-class> 
</servlet> 
<servlet-mapping> 
    <servlet-name>myServlet</servlet-name> 
    <url-pattern>/myServlet</url-pattern> 
</servlet-mapping> 

這應該工作根據一切在那裏,但點擊提交按鈕給了我一個HTTP Status 404(此網址:http://localhost:8080/myServlet)我重新啓動tomcat幾次,但它並不能幫助。我錯過了什麼?

編輯:tomcat log

127.0.0.1 - - [21/Sep/2015:17:31:55 +0300] "GET/HTTP/1.1" 404 951 
0:0:0:0:0:0:0:1 - - [21/Sep/2015:17:31:55 +0300] "GET /MyApp/ HTTP/1.1" 404 981 
0:0:0:0:0:0:0:1 - - [21/Sep/2015:17:32:16 +0300] "GET /MyApp/pages/appl.jsp HTTP/1.1" 200 1024 
0:0:0:0:0:0:0:1 - - [21/Sep/2015:17:32:21 +0300] "POST /myServlet HTTP/1.1" 404 971 
+1

您可以發佈tomcat的日誌? –

+0

你能在這裏展示從Tomcat一些日誌? – irvana

+0

以及位於文件系統中的「myServlet.class」文件在哪裏?粘貼的完整路徑 –

回答

0

如果你的項目(APP)被稱爲「myServlet」,我想你應該打一個網址,根據您所配置的方式看起來像http://localhost:8080/myServlet/myServlet