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})
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With