目录
HttpServletRequest request
JSPWriter out
HttpServletResponse response 客户端响应信息
HttpSession session
ServletContext application?? ?全局上下文对象
Exception exception
ServletConfig?config
Object?page
PageContext?pageContext?? 页面对象上下文
HttpServletRequest request
//用来获取请求携带的参数信息
String value = request.getParameter("key");
//用来设置接受请求参数时的字符集(POST)
request.setCharacterEncoding("UTF-8");
//用来存储一个值 ? 在另一个地方获取这个值
request.setAttribute("key",Object);
//用来获取上述过程存储的值
Object = request.getAttribute("key");
//用来设置转发的资源位置
RequestDispatcher rd = request.getRequestDispatcher("path");
//真正的转发
rd.forward(request,response);
//获取请求携带参数全部的key
Enumeration = request.getParameterNames();
//获取key一致的一组value值 通常用作复选框
String[] = request.getParameterValues("key");
StringBuffer = request.getRequestURL(); Uniform Resource Locator统一资源定位器
http://localhost:8080/JSPBuiltInObject/index.jsp
String = request.getRequestURI(); Uniform Resource Identifier统一资源标识符
/JSPBuiltInObject/index.jsp
//获取协议头传递的信息 国际化
request.getHeader("Accept-Language");
//获取Session对象
HttpSession = request.getSession();
JSPWriter out
out.write();
HttpServletResponse response 客户端响应信息
response.setCharacterEncoding("UTF-8");
PrintWriter pw = response.getWriter();?? ?pw.write("");
//获取状态响应码
int statusNumber = response.getStatus();
//设置响应码
response.setStatus(int statusNumber);
//Cookie是在客户端(浏览器端)存储的一个记录
response.addCookie(new Cookie("key","value"));//key不可以为null 且字符串长度不能为零
//用来做请求重定向
response.sendRedirect("path");
HttpSession session
session.setAttribute("key",Object);
Object = session.getAttribute("key");
session.removeAttribute("key");
Enumeration en = session.getAttributeNames();//获取全部的key
//设置session最大的不活跃时间 session出了这个时间间隔就不再活跃(无法获取session中的信息)
session.setMaxInactiveInterval(int 秒);
//设置session对象失效(session没有啦)
session.invalidate();
String JSessionID = session.getId();
ServletContext application?? ?全局上下文对象
//存值
application.setAttribute("key",Object);
//取值
Object = application.getAttribute("key");
//删除
application.removeAttributer("key");
Enumeration en = application.getAttributeNames();
String value = application.getInitParameter("key");
Enumeration en = application.getInitParameterNames();
application.getRequestDispatcher("").forwar(req,resp);
String realPath = application.getRealPath("/");
Exception exception
可以写一个新的jsp?? ?比如error.jsp 在error.jsp头信息上设置 ? ? isErrorPage="true" 在正常的jsp中设置头信息 ? errorPage="error.jsp"
ServletConfig?config
String value = config.getInitParameter("key");
Enumeration en = config.getInitParameterNames();
String name = config.getServletName();
ServletContext application = config.getServletContext();
Object?page
Object?page = this;当前页对象
index_jsp.java这个类的对象
PageContext?pageContext?? 页面对象上下文
pageContext.setAttribute();
pageContext.getAttribute();
pageContext.removeAttribute();
|