关于请求数据:
在jsp页面中:
pageContext.setAttribute(); //保存的数据只在一个页面中有效
request.setAttribute(); //保存的数据旨在一次请求中有效
session.setAttribute(); //保存的数据只在一次会话中有效
application.setAttribute(); //保存的数据只在服务器中有效
例如:
jsp中的部分代码:
<%
pageContext.setAttribute("name1","订单1号"); //保存的数据只在一个页面中有效
request.setAttribute("name2","订单2号"); //保存的数据旨在一次请求中有效
session.setAttribute("name3","订单3号"); //保存的数据只在一次会话中有效
application.setAttribute("name4","订单4号"); //保存的数据只在服务器中有效
%>
<html>
<head>
<title>页面第二</title>
</head>
<body>
<h1>这里是第二个页面,哈哈哈哈哈!</h1>
<%
String name1 = (String) pageContext.getAttribute("name1");
String name2 = (String) pageContext.getAttribute("name2");
String name3 = (String) pageContext.getAttribute("name3");
String name4 = (String) pageContext.getAttribute("name4");
String name5 = (String) pageContext.getAttribute("name5");
%>
<h1>取出的值为:
</h1>
<h2>${name1}</h2>
<h2>${name2}</h2>
<h2>${name3}</h2>
<h2>${name4}</h2>
<h2>${name5}</h2>
<h2><%=name5%></h2>
此时运行结果为:
将以下部分代码注释之后再次访问页面,并在另一个浏览器中也再次访问:
结果如下图: