1,
javax.servlet
Interface RequestDispatcher
void forward(ServletRequest request,
ServletResponse response)
throws ServletException,
IOException
forward
should be called before the response has been committed to the client (before response body output has been flushed). If the response already has been committed, this method throws an IllegalStateException
.
API 中 规定 :forward 方法需要在 response 被提交之前调用,那么 什么时候 response 才会被提交呢?
假设 paraResponse 是 service 方法的 response 参数,
PrintWriter pw = paraResponse.getWriter();
paraResponse.isCommitted(); // false
pw.close(); // close 之后 ,response 就会被提交
paraResponse.isCommitted(); // true
2,addservlet 和 createservlet servlet context methods
3,ServletConfig ServletContext getInitParameter
4, ServletContext ServletRequest get / setAttribute
5, ServletRequest async-supported 设置方法:
(1)配置servlet参数<async-supported>true</async-supported>
,
(2)或通过注解方式启用@WebServlet(urlPatterns = "/demo",asyncSupported = true)
(3) request.setAttribute("org.apache.catalina.ASYNC_SUPPORTED", true);
6, 如何让服务器生成 sessionID ?
只有 extends HttpServlet 并且 调用 request.getSession() ; 服务器才会生成 session 并且 在 Response Header 中
生成 set-cookie:JSESSIONID=*********