jsp_属性范围_request

request属性范围表示在服务器跳转后,所有设置的内容依然会被保留下来。(服务器端跳转:页面跳转,地址栏不发生变化)

下面写个小例子测试下:

(1)request_demo.jsp

 <%@ page contentType="text/html; charset=utf-8" language="java"     errorPage="" %>
<%@ page import="java.util.*"%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>page属性范围</title>
</head> <body>
<%
request.setAttribute("name","ninic");
request.setAttribute("birthday",new Date());
%>
<jsp:forward page="request_demo2.jsp"/>
</body>
</html>

(2)request_demo2.jsp

 <%@ page contentType="text/html; charset=utf-8" language="java" import="java.util.*" errorPage="" %>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head> <body>
<%
String username=(String)request.getAttribute("name");
Date userbirthday=(Date)request.getAttribute("birthday");
%>
<h2>姓名:<%=username%></h2>
<h2>生日:<%=userbirthday%></h2>
</body>
</html>

浏览器中显示:

jsp_属性范围_request

上一篇:云告警平台 OneAlert :如何帮助运维工程师做好汇报?


下一篇:unity技巧