One: Page Property scope
<%@ page language="java"import="java.util.*" pageencoding="UTF-8"%>
<%@ taglib prefix="C"uri="Http://java.sun.com/jsp/jstl/core" %>
<! DOCTYPE HTML Public "-//w3c//dtdhtml 4.01 transitional//en" >
<title>my JSP ' jspobj.jsp ' starting page</title>
<body>
<%
These properties can only be useful on the current JSP page
Pagecontext.setattribute ("name", "China");
Pagecontext.setattribute ("History", "5000");
%>
<%
Remove attributes and transform downward
Stringcityname= (String) pagecontext.getattribute ("name");
stringcityhistory= (String) Pagecontext.getattribute ("History");
%>
</body>
II: request attribute Range
<%@ page language="java"import="java.util.*" pageencoding="UTF-8"%>
<%@ taglib prefix="C"uri="Http://java.sun.com/jsp/jstl/core" %>
<! DOCTYPE HTML Public "-//w3c//dtdhtml 4.01 transitional//en" >
<title>my JSP ' jspobj.jsp ' starting page</title>
<body>
<%
Request property, only works in server jump
Request.setattribute ("req", "request Attribute");
Request.setattribute ("Reuse", "function only in server Jump");
%>
<jsp:forward page="demo3.jsp"/>
</body>
demo3.jsp
<%@ page language="java"import="java.util.*" pageencoding="UTF-8"%>
<%@ taglib prefix="C"uri="Http://java.sun.com/jsp/jstl/core" %>
<! DOCTYPE HTML Public "-//w3c//dtdhtml 4.01 transitional//en" >
<title>my JSP ' Demo3. JSP' starting page</title>
<body>
<%
Stringreque= (String) request.getattribute ("req");
Stringreuse= (String) Request.getattribute ("reuse");
%>
</body>
Three: Session attribute range
<%@ page language="java"import="java.util.*" pageencoding="UTF-8"%>
<%@ taglib prefix="C"uri="Http://java.sun.com/jsp/jstl/core" %>
<! DOCTYPE HTML Public "-//w3c//dtdhtml 4.01 transitional//en" >
<title>my JSP ' jspobj.jsp ' starting page</title>
<body>
<%
Session.setattribute ("Sename", "Session attribute range");
Session.setattribute ("Seuse", "always valid in one browser");
%>
<!--address change, client jumps--
<a href="demo4.jsp"> Hyperlinks Get Properties </a>
</body>
demo4.jsp
<%@ page language="java"import="java.util.*" pageencoding="UTF-8"%>
<%@ taglib prefix="C"uri="Http://java.sun.com/jsp/jstl/core" %>
<! DOCTYPE HTML Public "-//w3c//dtdhtml 4.01 transitional//en" >
<title>my JSP ' Demo4. JSP' starting page</title>
<body>
<%
Stringsename= (String) session.getattribute ("Sename");
Stringseuse= (String) session.getattribute ("Seuse");
%>
</body>
Four: Application attribute range
<%@ page language="java"import="java.util.*" pageencoding="UTF-8"%>
<%@ taglib prefix="C"uri="Http://java.sun.com/jsp/jstl/core" %>
<! DOCTYPE HTML Public "-//w3c//dtdhtml 4.01 transitional//en" >
<title>my JSP ' jspobj.jsp ' starting page</title>
<body>
<%
Application.setattribute ("Apname", "Application attribute range");
Application.setattribute ("Apuse", "Set on server Side");
%>
<!--address change, client jumps--
<a href="demo4.jsp"> Hyperlinks Get Properties </a>
</body>
demo4.jsp
<%@ page language="java"import="java.util.*" pageencoding="UTF-8"%>
<%@ taglib prefix="C"uri="Http://java.sun.com/jsp/jstl/core" %>
<! DOCTYPE HTML Public "-//w3c//dtdhtml 4.01 transitional//en" >
<title>my JSP ' Demo4. JSP' starting page</title>
<body>
<%
Stringapname= (String) application.getattribute ("Apname");
Stringapuse= (String) application.getattribute ("Apuse");
%>
</body>
These are very basic concepts, they have to read more books, broaden their knowledge!
qq:1327880701
Copyright Notice: Bo Master original articles, reproduced please indicate the source. Http://blog.csdn.net/dzy21
JSP four attribute ranges