Java servlet annotation
•
Java
Is there a way to map URLs to methods using pure Java servlets instead of spring MVC request mapping?
It's like:
@GET(/path/of/{id})
Solution
It can also use "ordinary vanilla" servlets (alas, spring MVC and jax-rs are also built on the servlet API), and it only needs more templates
@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 it. Thanks to the new servlet 3.0 @ webservlet annotation, you don't need any web XML entry
You can also see:
> Our Servlets wiki page
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码