netstorelookupdispatchaction.java

来自「基于servlet/xml开发的网上书店 下载有需写web.xml配置」· Java 代码 · 共 61 行

JAVA
61
字号
package netstore.framework;import javax.servlet.http.*;import netstore.framework.util.IConstants;import netstore.service.INetstoreService;import netstore.service.INetstoreServiceFactory;import org.apache.struts.actions.LookupDispatchAction;abstract public class NetstoreLookupDispatchAction extends LookupDispatchAction {  protected INetstoreService getNetstoreService(){    INetstoreServiceFactory factory = (INetstoreServiceFactory)getApplicationObject( IConstants.SERVICE_FACTORY_KEY );    INetstoreService service = null;    try{      service = factory.createService();    }catch( Exception ex ){      log.error( "Problem creating the Netstore Service", ex );    }    return service;  }  /**   * Retrieve an object from the application scope by its name. This is   * a convience method.   */  protected Object getApplicationObject(String attrName) {    return servlet.getServletContext().getAttribute(attrName);  }  /**   * Retrieve the SessionContainer for the user tier to the request.   */  protected SessionContainer getSessionContainer(HttpServletRequest request) {    SessionContainer sessionContainer = (SessionContainer)getSessionObject(request, IConstants.SESSION_CONTAINER_KEY);    System.out.println( sessionContainer );    // Create a SessionContainer for the user if it doesn't exist already    if(sessionContainer == null) {      sessionContainer = new SessionContainer();      sessionContainer.setLocale(request.getLocale());      HttpSession session = request.getSession();      session.setAttribute(IConstants.SESSION_CONTAINER_KEY, sessionContainer);    }    return sessionContainer;  }  /**   * Retrieve a session object based on the request and the attribute name.   */ protected Object getSessionObject(HttpServletRequest req,                                    String attrName) {    Object sessionObj = null;    HttpSession session = req.getSession(false);    System.out.println( "Session was " + session );    if ( session != null ){       sessionObj = session.getAttribute(attrName);    }    return sessionObj;  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?