Java Servlet Annotations

Is it possible to use pure Java Servlets rather than spring mvc request to map url to method?

something like:

@GET(/path/of/{id})

      

+3


source to share


1 answer


Also possible with "plain vanilla" servlets (heck, Spring MVC and JAX-RS are also built on top of the servlet API), it only requires a little more boilerplate.

@WebServlet("/path/of/*")
public class PathOfServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getPathInfo().substring(1);
        // ...
    }

}

      

It's all. Thanks to the new Servlet 3.0 annotation, @WebServlet

you don't need to write web.xml

.



See also:

+7


source







All Articles