This is the code I'm using:
public class MyServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// whatever I need to do
}
}
The JSP
:
<form action="/myServlet" method="post">
<input type="submit" value="Submit">
</form>
In 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>
This should work according to everything out there but clicking the submit button gives me a HTTP Status 404
(for this url: http://localhost:8080/myServlet
.) I restarted tomcat
several times but it doesn't help. What am I missing?
EDIT: the 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