📄 sessioncontainer.java
字号:
package netstore.framework;
import java.util.Locale;
import javax.servlet.http.HttpSessionBindingListener;
import javax.servlet.http.HttpSessionBindingEvent;
import netstore.businessobjects.Customer;
/**
* Used to store information about a specific user. This class is used
* so that the information is not scattered throughout the HttpSession.
* Only this object is stored in the session for the user. This class
* implements the HttpSessionBindingListener interface so that it can
* be notified of session timeout and perform the proper cleanup.
*
* 用来存贮客户数据,不通过HttpSession存
* 这个类实现了HttpSessionBindingListener接口
* 所以能够被session超时唤醒,执行相应清理动作
*/
public class SessionContainer implements HttpSessionBindingListener {
// The user's shopping cart
//购物车
private ShoppingCart cart = null;
// Data about the user that is cached
//客户对象本身
private Customer customer = null;
private String currentOrderNumber=null;
/**
* The Locale object for the user. Although Struts stores a Locale for
* each user in the session, the locale is also maintained here.
*/
private Locale locale;
/**
* Default Constructor
*/
public SessionContainer() {
super();
initialize();
}
/**
* The container calls this method when it is being unbound from the
* session.
*/
public void valueUnbound(HttpSessionBindingEvent event) {
// Perform resource cleanup
System.out.println( "Being unbound...");
cleanUp();
}
public ShoppingCart getCart() {
return cart;
}
public void setCart(ShoppingCart newCart) {
cart = newCart;
}
public String getCurrentOrderNumber() {
return currentOrderNumber;
}
public void setCurrentOrderNumber(String currentOrderNumber) {
this.currentOrderNumber = currentOrderNumber;
}
/**
* Set the locale for the user.
*/
public void setLocale(Locale aLocale) {
locale = aLocale;
}
/**
* Retrieve the locale for the user.
*/
public Locale getLocale() {
return locale;
}
/**
* The container calls this method when it is being bound to the
* session.
*/
public void valueBound(HttpSessionBindingEvent event) {
// Don't need to do anything, but still have to implement the
// interface method.
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
/**
* Initialize all of the required resources
*/
private void initialize() {
// Create a new Shopping cart for this user
cart = new ShoppingCart();
}
/**
* Clean up any open resources. The shopping cart is left intact
* intentionally.
*/
public void cleanUp() {
setCustomer( null );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -