這是我使用的代碼:從形式調用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
您可以發佈tomcat的日誌? –
你能在這裏展示從Tomcat一些日誌? – irvana
以及位於文件系統中的「myServlet.class」文件在哪裏?粘貼的完整路徑 –