I am a little confused on HttpServlet usage of @Path(“/path”) with an @POST method versus doPost(HttpServletRequest request, HttpServletResponse response) method. I have seen many good working examples of the @Path usage but never a working example of the doPost. When ever I attempt to use the doPost it never gets called.
First, what’s the difference, and which is a better way to go? Also, what am I doing wrong with the doPost
public class PostExample extends HttpServlet{
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
// HttpServlet doPost never gets called
System.out.println("hit test doPost "+request.getRequestURI());
}
}
Thanks!
The annotation @GET, @PUT, @POST, @DELETE and @HEAD are part of JAX-RS: Java API for RESTful Web Services specification to specify the HTTP request type of a resource and are implemented in Web Service frameworks like Jersey and Apache CXF and you won’t be using them until you actually use those frameworks.
Wiki JAX-RS
You need to specify the servlet in your web.xml