这是我正在使用的代码:
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
答案 0 :(得分:0)
如果你的项目(app)被称为'myServlet',我认为你应该按照你配置的方式点击一个看起来像http://localhost:8080/myServlet/myServlet
的网址。
答案 1 :(得分:0)