JSP_ Attribute Range _page

Source: Internet
Author: User

The page property range (denoted by PageContext, but is generally used to refer to this range as the page range) indicates that a property is set on this page and cannot be obtained after the page jumps.

Let's write two small examples to test:

1. Set a property on the same JSP page and take out the properties:

1<%@ page contenttype= "text/html; Charset=utf-8 "language=" java "errorpage=" "%>2<%@ pageImport= "Java.util.*"%>3<!doctype html>456<meta charset= "Utf-8" >7<title>page Attribute Range </title>89 Ten<body> One<% APagecontext.setattribute ("name", "Ninic"); -Pagecontext.setattribute ("Birthday",NewDate ()); -%> the<% -String Username= (String) pagecontext.getattribute ("name"); -Date userbirthday= (date) pagecontext.getattribute ("Birthday"); -%> + - +</body> A

Displayed in the browser:

2. Set properties on different pages and remove attributes

(1) page_demo.jsp

1<%@ page contenttype= "text/html; Charset=utf-8 "language=" java "errorpage=" "%>2<%@ pageImport= "Java.util.*"%>3<!doctype html>456<meta charset= "Utf-8" >7<title>page Attribute Range </title>89 Ten<body> One<% APagecontext.setattribute ("name", "Ninic"); -Pagecontext.setattribute ("Birthday",NewDate ()); -%> the<jsp:forward page= "page_demo2.jsp"/> -</body> -

(2) page_demo2.jsp

1<%@ page contenttype= "text/html; Charset=utf-8 "Language=" Java "Import= "java.util.*" errorpage= ""%>2<!doctype html>345<meta charset= "Utf-8" >6<title> Untitled Document </title>78 9<body>Ten<% OneString Username= (String) pagecontext.getattribute ("name"); ADate userbirthday= (date) pagecontext.getattribute ("Birthday"); -%> - the -</body> -

Displayed in the browser:

JSP_ Attribute Range _page

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.