JSP entry primary guide the use of the Session

Author:Anonymous    Updated:2008-2-26 22:06:27
TTP is no agreement of the state, that is, the information can not be passed into the HTTP protocol itself transmission. In order to track the operation of state users, ASP Application SESSION object. Using a JSP is the object of HttpSession achieve the same function. HTTPSession is a built-cookies and URL rewriting on the quality of the interface. Session information stored in the server side, the id Session stored in the cookie in the client. In fact, in many servers, if the browser if they support the use of cookies, but if you do not support or repealed because it will automatically translate into URL-rewriting, the process for each session automatically, providing a convenient way to store information.

General Session on the server installed with a 30-minute time expired, when a customer ceased operations after expire automatically. Session in the preservation and retrieval of information, it is not the basic data types such as int, double, and so on, must be java and the corresponding object, such as Integer, Double.

Httpsession API is as follows:

GetId this method returns the only logo, the logo for each session and produce. When only a single value with a joint session, or when the log information related to the previous sessions, it was used as keys.

GetCreationTime been created to return to session time. The smallest unit of 1/1000th of a second. To get a very useful for printing output value, this value can be passed or GregorianCalendar Date constructor method setTimeInMillis.

GetLastAccessedTime returned to the session, was sent last time. The smallest unit of 1/1000th of a second.

GetMaxInactiveInterval return to the total time (seconds), said that negative session never overtime.

GetAttribute from a session linked to the information. (Jsp1.0 for getValue)

Integer item = (Integer) session.getAttrobute ( "item") / / Retrieval and the value of the session into an integer

SetAttribute provide a keyword and a value. Will replace any previous value. (Jsp1.0 for putValue)

Session.setAttribute ( "ItemValue" itemName); / / ItemValue must not be simple type

Most used in the application is getAttribute and setAttribute. Is a simple example to illustrate the application session, test1.jsp (information into the session), test2.jsp (from the session read out information).

Test1.jsp

<HTML>

<HEAD>

<TITLE> Document </ TITLE>

</ HEAD>

<BODY BGCOLOR="#FFFFFF">
Session.setAttribute ( "str", the new String ( "this is test"));
</ BODY>

</ HTML>
Test2.jsp
<HTML>

<HEAD>
<TITLE> New Document </ TITLE>

</ HEAD>

<BODY BGCOLOR="#FFFFFF">
<%
String ls_str = null;
Ls_str = (String) session.getAttribute ( "str");
Out.println ( "removed from the session, the value is:" + ls_str);
%>
</ BODY>

</ HTML>
Previous:JSP enhance the unique skills of the seven applications
Next:Taglib principle and the support of El expression
User Reviews
Related Articles
Recommended article
AD