四大域对象复习

四大域对象作用范围与常用方法

PageContext:范围在JSP本页面面
setAttribute();
getAttribute();

HttpRequest:范围一个请求中(请求转发)
setAttribute();
getAttribute();
getParameter(String key)

HttpSession:会话(范围:浏览器就一定丢失 重定向)
setAttribute();
getAttribute();
removeAttribute(String key)
setMaxInactiveInterval(int seconds);销毁时间
invalidate(); 让seeeion失效

SeverletContext:服务器共享(记录网站访问次数)
setAttribute();
getAttribute();
String getRealPath("/"):获取tomcat项目中的路径

Servlet初始化参数:
1.在servlet中定义参数
2.在全局中定义参数

处理乱码

1.get请求到后台server.xml设置端口处加 URIEnocoding=“utf-8”
2.post请求到后台requset.setCharacterEncoding(“utf-8”)
3.响应到前端: response.setContentType(“text/html;charset=utf-8”)

发布了5 篇原创文章 · 获赞 1 · 访问量 83

猜你喜欢

转载自blog.csdn.net/weixin_45570207/article/details/104472397