02_02 Four property scopes for JSP built-in objects

Source: Internet
Author: User

Four range of attributes

Property Scope Overview

Page The property is saved in only one page and is not valid after the jump.

Request The attribute is saved only in one request and is still valid after the server jumps.

Session saved in a session scope, regardless of which jumps are valid. However, the new browser cannot be used.

applictation saved on the entire server and available to all users.

4 built-in objects support the following three methods of operation:

NO

Method name

Type

Describe

1

public void SetAttribute (String name, Object o)

Ordinary

Set the name and content of a property

2

Public Object getattribute (String name)

Ordinary

Get attribute Content

3

public void RemoveAttribute (String name)

Ordinary

Delete Property

1.page attribute Range (PageContext)

The current Page setting property is valid, the page jump is not valid

Example 1 setting properties within a page and getting properties

<%--page property: Setting the current page is valid, jumping is not valid--%><%@ page contenttype= "text/html" pageencoding= "GBK"%><%@ page Import = "java.util.*"%> <%--Guide java.util pack--%>


Example 2 setting properties within a page but jumping page Get Properties (unsuccessful)

<%--page property: Setting the current page is not valid, jumping is not valid--%><%@ page contenttype= "Text/html"  pageencoding= "GBK"%><%@ page import= "java.util.*"%>     <%--Guide Java.util Bag--%>
<%--page property: Setting the current page is valid, jumping is not valid--%><%@ page contenttype= "text/html" pageencoding= "GBK"%><%@ page Import = "java.util.*"%> <%--Guide java.util pack--%>


2.request Properties

The server jump property is valid, but the client jump property is not valid.

Example 1 server Jump property is valid

<%--request property:  Server Jump Property valid--%><%@ page contenttype = "text/html"  pageencoding= "GBK"%><%@ page import= "java.util.*"%>     <%--Guide Java.util Bag--%>
<%--request Properties: Server Jump Property Valid--%><%@ page contenttype= "text/html" pageencoding= "GBK"%><%@ page import= " Java.util.* "%> <%--Guide java.util pack--%>

Example 2 Invalid client Jump property

<%//set the Request property range, this property server jump property is valid Request.setattribute ("name",  "Zheng Lian" ); Request.setattribute ("Birthday",  new date ());%><!--through hyperlink jump, belong to the client jump, the address bar has changed Oh--><a  href= "request_scope_02.jsp" > via hyperlink Get Properties </a></body>
<%--request Properties: Server Jump Property Valid--%><%@ page contenttype= "text/html" pageencoding= "GBK"%><%@ page import= " Java.util.* "%> <%--Guide java.util pack--%>

3.session Properties

Session Properties are valid in a browser, whether the server jumps or the client jumps.

Cases

<%--session Properties: Properties are valid in one browser--%><%@ page contenttype= "text/html" pageencoding= "GBK"%><%@ page import= " Java.util.* "%> <%--Guide java.util pack--%>
<%--session Properties: Properties are valid in one browser--%><%@ page contenttype= "text/html" pageencoding= "GBK"%><%@ page import= " Java.util.* "%> <%--Guide java.util pack--%>

But the new browser will not be able to get the property (to close the original browser OH)

4.application Properties

Application attribute scope, this property is saved on the server

Cases

<%--application property Scope, this property is saved on the server--%><%@ page contenttype= "text/html" pageencoding= "GBK"%><%@ page Import= "java.util.*"%> <%--Guide java.util pack--%>
<%--application property Scope, this property is saved on the server--%><%@ page contenttype= "text/html" pageencoding= "GBK"%><%@ page Import= "java.util.*"%> <%--Guide java.util pack--%>

The properties are valid as long as the server does not restart, and the server restart is not valid.

applictaion too many properties can affect server performance and use them with caution.

So using the attribute principle

You can use page to use page; You can use request to request, you can use session with the session, and use application with caution.


The above content reference Javaweb development actual combat Classics (teacher pulpit)


This article is from the "Beyond the Horizon" blog, be sure to keep this source http://udbful.blog.51cto.com/10601869/1683104

02_02 Four property scopes for JSP built-in objects

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.