Home > 类库下载 > java类库 > body text

JAVA WEB scope

高洛峰
Release: 2016-10-20 11:30:51
Original
1782 people have browsed it

, page attribute scope (pageContext)

  a. Attributes set on one page cannot be accessed when jumping to other pages (including redirection and).

  Example: pageScopeDemo01.jsp
   

   

   

   

   

   

page attribute scope (pageContext )

  

  

  

    //Attributes set at this time Can only be obtained on this page

   pageContext.setAttribute("name","League of Legends");//Set attributes

   pageContext.setAttribute("date",new Date()); //Set attributes

    / /Note: The names of the two attributes set here are name and date. These two are string type data, but the corresponding attribute values ​​​​League of Legends and new Date are not string types, but two Object type data.

   %>

  

      //Get the set attribute

    String refName = (String)pageContext.getAttribute("name");

      Since the value obtained is of Object type, String coercion must be used Downcast to String type

    Date refDate = (Date)pageContext.getAttribute("date");  

  

b. Here, if you need to check, use the jsp:forward tag to jump to the server side.

 Example:

 c. The jump page here includes redirection (the URL on the client side changes) and forwarding (the URL on the server side does not change, and the server side jumps).

2. Request attribute range

a. The request attribute range means that it is valid in a server jump. As long as the server jumps (forwarding or dispatching), the set request attribute can be passed on.

3. Session attribute range

 a. The attributes set by session can be obtained no matter how you jump. Of course, session is only for one user

b. After jumping (server jump/client jump) to other pages, the attributes set on the first page can still be obtained by other pages. properties.

  c. Whether it is a client-side jump or a server-side jump, you can access the session attribute set on the first page, but the condition is that it is only limited to the current user. If a new browser is opened at this time, the session attribute value cannot be accessed.

4. Application attribute scope

a. The application attribute scope is an attribute set on the server, so once set, any user can browse to this attribute.

b. If you shut down the Tomcat server and then restart it, open a browser window and run it, and directly get the value set by the application attribute, you will not be able to get it.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!