Java Servlet Annotations
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 to share