Request/Response
概念:
Request:对应的是客户的请求(web开发中最重要的一个对象)
Response:对应的就是服务器给我发过来的响应
Web开发中四大域对象:
pageContext(当前页面)
request(HttpServletRequest) 作用范围:转发页面之间的通信
session(HttpSession) 作用范围:同一个会话(session)
application(ServletContext) 作用范围:在web应用下都可以传递
Request对象的方法:
void setAttribute(String name, Object obj);
void getAttribute(String name, Object obj);
String getParameter(String name);
Enumeration<String> getParameterNames();
HttpSession getSession();
Cookie[] getCookies();
String getContextPath();
RequestDispatcher getRequestDispatcher(String path);
备注:Request对象的所有方法都要好好看API一遍,上述的是开发中最为常用的一些方法。
Response对象的方法:
void addCookie(Cookie cookie);
ServletOutputStream getOutputStream();
PrintWriter getWriter();
void sendRedirect(String location);
还有设置一些返回头信息、状态信息等有兴趣的话,可以自己看看api.