Jsp session usage and attribute range

Source: Internet
Author: User
Tags unique id


Session attribute range

In the range of one session, no matter what type of jump can be used, but the new browser will not be able to use

Set the session attribute range to session_scope_01.jsp.

The code is as follows: Copy code

<%
Session. setAttribute ("name", "James ");
Session. setAttribute ("birthday", new Date ());
%>
<A href = "session_scope_02.jsp"> session jump </a>

Session_scope_02.jsp


<%
String username = (String) session. getAttribute ("name ");
Date birthday = (Date) session. getAttribute ("birthday ");
%>
<H1> <% = username %> <H2> <% = birthday %>

No matter whether the user calls session_scope_01.jsp or session_scope_02.jsp, java bean UserEnv is always initialized first. Because the bean has a seesion cycle, the user needs to call it after the second time within the seesion validity period, myenv. getUserdir () will read the variable directly from the bean memory without initialization. this increases the speed and reduces the database access volume.

 


Note: add two jsp file headers

<% @ Page language = "java" contentType = "text/html" pageEncoding = "UTF-8" %>

<% @ Page import = "java. util. *" %>

A session object refers to a session between the client and the server, starting from a WebApplication that the client connects to the server until the client and the server are disconnected. It is an instance of the HttpSession class.

Serial number method description
1 long getCreationTime () returns the SESSION creation time
2 public String getId () returns the unique ID number set by the JSP Engine during SESSION creation.
3 long getLastAccessedTime () returns the last client request time in this SESSION
4 int getMaxInactiveInterval () returns the interval between two requests this SESSION is canceled (MS)
5 String [] getValueNames () returns an array containing all the available attributes of this SESSION.
6 void invalidate () cancels the SESSION and makes the SESSION unavailable
7 boolean isNew () returns a SESSION created by the server, whether the client has been added
8 void removeValue (String name) deletes the attribute specified in the SESSION.
9 void setMaxInactiveInterval () sets the interval between two requests this SESSION is canceled (MS)

Related Article

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.