One of the problems with storing data in (Web hosting account)

One of the problems with storing data in the HttpSession is that the interface to store and retrieve data from the session object is not strongly typed. In other words, the interface for any data is: public void setAttribute( “permissionsKey”, permissions ); public Object getAttribute( “permissionsKey” ); The client must be aware of the key at which the data is stored in order to put an object into or retrieve an object from storage. Some programmers prefer a more strongly typed interface instead: userContainer.setPermissions( permissions ); userContainer.getPermissions( ); Here, the client doesn’t have to worry about what key the object is being stored under or how it’s being stored. It can be an HttpSession object or some other data store; the client is not made aware of this because it’s not forced to use the methods of the HttpSession directly. There’s nothing really complicated about the UserContainer class itself. It’s an ordinary JavaBean that contains instance variables, along with public getters and setters for the properties. Example 9-5 illustrates a basic UserContainer class. Example 9-5. A basic UserContainer class package com.oreilly.struts.storefront.framework; import java.util.Locale; import javax.servlet.http.HttpSessionBindingListener; import javax.servlet.http.HttpSessionBindingEvent; import com.oreilly.struts.storefront.customer.view.UserView; /** * Used to store information about a specific user. This classis used * so that the information is not scattered throughout theHttpSession. * Only this object is stored in the session for the user. This class * implements the HttpSessionBindingListener interface so thatit can * be notified of session timeout and perform the propercleanup. */ public class UserContainer implementsHttpSessionBindingListener { // The user’s shopping cart private ShoppingCart cart = null; // Data about the user that is cached private UserView userView = null; /**
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

Leave a Reply