9大内置对象
request | HttpServletRequet |
response | HttpServletResponse |
session | HttpSession |
application | ServletContext |
config | ServletConfig |
exception | Throwable |
page | Object |
pageContext | PageContext |
out | JspWriter |
四大域对象
作用:
保存数据 和 获取数据 ,用于数据共享。
方法:
-
向域对象中存值:
setAttribute(key,value); -
从域对象中取值:
一个值:getAttribute(key) - 返回类型:Object
多个值:request.getParameterValues(“name”);
所有参数:request.getParameterNames(); -
从域对象中移除某个键值
removeAttribute(key)
作用范围:
- HttpServletRequest - request: 作用范围:一次请求
- HttpSession - session: 作用范围:一次会话
- PageContext - pageContext : 作用范围:当前页面
- ServletContext - application:作用范围:服务器的整个生命周期
初始化
- HttpSession session = request.getSession();//获取session对象
- ServletContext application = getServletContext();
接受数据关于编码问题
(1)修改POST方式参数编码:
request.setCharacterEncoding(“utf-8”);
(2)修改GET方式参数编码:
手动解码:String name = new String(name.getBytes(“ISO-8859-1”),“utf-8”);