29.01.2013 Views

WebSphere Application Server - IBM Redbooks

WebSphere Application Server - IBM Redbooks

WebSphere Application Server - IBM Redbooks

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Item Folder/Package Description<br />

CurrentCustomer.jsp wishlist This page receives the user and<br />

password information from<br />

managewishlist.jsp. The page<br />

verifies that the user exists and<br />

submits the wishlist contents and<br />

customer information to the order<br />

table. Is also updates the quantity<br />

item table in the SALESAPP<br />

database and removes all the items<br />

from the wishlist. If the user does not<br />

exist then the user is informed of the<br />

error and is asked to try again or to<br />

register as a new customer using<br />

AddNewCustomer.html.<br />

HttpSession<br />

The HttpSession class supports built-in session tracking between the client and<br />

the server, by user. The Web container provides an implementation of the<br />

HTTPSession interface giving the application’s Web components access to the<br />

methods of the HTTPSession interface.<br />

The container recognizes a user by assigning him or her a unique session<br />

identifier. An object is associated with this identifier and the servlet may store,<br />

retrieve, and remove objects from this user session. The objects belong to a<br />

particular session and represent the session data for a particular user.<br />

Every time the client makes a request, the servlet gets the session object<br />

associated to him or her through the identifier (a new session is created if the<br />

user does not have any) and performs operations on it.<br />

The session identifiers are managed by the container which ensures that there is<br />

one session for each user. The API provides methods to destroy a session,<br />

typically used when a user logs out.<br />

The following shows an example of handling the HttpSession objects; this code<br />

can be included in the service method of a servlet.<br />

Example: C-1 Using the HttpSession interface<br />

HttpSession session = request.getSession(true);<br />

if (session.isNew()) {<br />

// perform actions for a new user<br />

...<br />

// set an attribute in the user session<br />

Appendix C. Online Catalog application 623

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!