当前位置: 代码迷 >> 综合 >> JavaWeb-jsp-九大内置对象
  详细解决方案

JavaWeb-jsp-九大内置对象

热度:89   发布时间:2023-11-08 04:21:11.0

1.九大对象名字

  • PageContext 存东西

  • Request 存东西

  • Response

  • Session 存东西

  • Application 【SerlvetContext】 存东西

  • config 【SerlvetConfig】

  • out

  • page ,不用了解

  • exception

2.常用的四个

<%pageContext.setAttribute("teacher","苍老师");//保存数据在一个页面中有效request.setAttribute("teacher1","滕老师");//保存数据在一次请求中有效,请求转发携带数据session.setAttribute("teacher2","小泽老师");//保存数据在一次会话中有效application.setAttribute("teacher3","波多老师");//保存数据在服务器中有效,
%>

3.使用小例

<html>
<head><title>Title</title>
</head>
<body>
<%-- 内置对象--%>
<%pageContext.setAttribute("teacher","苍老师");//保存数据在一个页面中有效request.setAttribute("teacher1","滕老师");//保存数据在一次请求中有效,请求转发携带数据session.setAttribute("teacher2","小泽老师");//保存数据在一次会话中有效application.setAttribute("teacher3","波多老师");//保存数据在服务器中有效,
%>
<hr>
<%String teacher= (String) pageContext.getAttribute("teacher");String teacher1= (String) request.getAttribute("teacher1");String teacher2= (String) session.getAttribute("teacher2");String teacher3= (String) application.getAttribute("teacher3");%>
<%-- s使用EL表达式输出 ${}--%>
<h3>${teacher}</h3>
<h3>${teacher1}</h3>
<h3>${teacher2}</h3>
<h3>${teacher3}</h3>
<hr></body>
</html>

 

4.课后小结

request:客户端向服务器发送请求,产生的数据,用户看完就没用了,比如:新闻,用户看完没用的!

session:客户端向服务器发送请求,产生的数据,用户用完一会还有用,比如:购物车;

application:客户端向服务器发送请求,产生的数据,一个用户用完了,其他用户还可能使用,比如:聊天数据;