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”);
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/117406.html