0

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 
Eddy
  • 3,533
  • 13
  • 59
  • 89

2 Answers2

0

If your project(app) is called 'myServlet', I think you should be hitting a url that looks like http://localhost:8080/myServlet/myServlet according to the way you have configured.

yogidilip
  • 790
  • 6
  • 21
0

Try with:

http://localhost:8080/MyApp/myServlet

Seems that your App name is "MyApp"

David Herrero
  • 704
  • 5
  • 17