3
通过引入Servlet 3.0,我们可以使用annotations将servlet映射到URL模式,并在web.xml中省略映射。JSP servlet映射
我不知道是否有一些intstructions或特殊标签允许JSP映射在页面代码URL,而不在web.xml
通过引入Servlet 3.0,我们可以使用annotations将servlet映射到URL模式,并在web.xml中省略映射。JSP servlet映射
我不知道是否有一些intstructions或特殊标签允许JSP映射在页面代码URL,而不在web.xml
声明的servlet有这样的无工厂。
最好的你可以做的是隐藏在/WEB-INF
的JSP(以便它不能直接通过URL请求)和刚刚创建,其转发给JSP servlet并最终绘制它所需的URL模式。这也很容易:
@WebServlet("/foo")
public class FooServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.getRequestDispatcher("/WEB-INF/foo.jsp").forward(request, response);
}
}
这样的JSP中/WEB-INF/foo.jsp
可通过http://localhost:8080/context/foo
。您可以使用front controller pattern将它进一步抽象为一个JSP的一个servlet。