JSP four attribute ranges

Source: Internet
Author: User
Tags ranges

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.