4

Is there any way to use pure Java servlets not spring mvc request mapping to map a URL to a method?

something like:

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

1 Answer 1

7

It's also possible with "plain vanilla" servlets (heck, Spring MVC and JAX-RS are also built on top of servlet API), it only requires a little bit 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);
        // ...
    }

}

That's all. Thanks to the new Servlet 3.0 @WebServlet annotation, you don't need any web.xml entry.

See also:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.