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})
“plain vanilla” servlet 也可以实现(见鬼,Spring MVC 和 JAX-RS 也构建在 servlet API 之上),它只需要更多样板。
@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);
// ...
}
}
就这样。感谢新的 Servlet 3.0@WebServlet
注释,您不需要任何web.xml
条目。