netstorelookupdispatchaction.java

来自「网上商店 新增功能: 1」· Java 代码 · 共 104 行

JAVA
104
字号
package netstore.framework;import javax.servlet.http.*;import netstore.framework.util.IConstants;import netstore.service.*;import org.apache.struts.actions.LookupDispatchAction;/** * 一个表单中多个按钮 button.checkout = Check Out button.saveorder = Save Order *  * 在Action中 getKeyMethodMap(){ Map map = new HashMap(); * map.put("button.checkout","checkout"); ......... } *  * @author huangyongfeng *  */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;	}	protected CustServiceImpl getCustService() {		INetstoreServiceFactory factory = (INetstoreServiceFactory) getApplicationObject(IConstants.SERVICE_FACTORY_KEY);		CustServiceImpl service = null;		try {			service = factory.createCustService();		} catch (Exception ex) {			log.error("Problem creating the Netstore Service", ex);		}		return service;	}	protected ProdServiceImpl getProdService() {		INetstoreServiceFactory factory = (INetstoreServiceFactory) getApplicationObject(IConstants.SERVICE_FACTORY_KEY);		ProdServiceImpl service = null;		try {			service = factory.createProdService();		} catch (Exception ex) {			log.error("Problem creating the Netstore Service", ex);		}		return service;	}	protected OrderServiceImpl getOrderService() {		INetstoreServiceFactory factory = (INetstoreServiceFactory) getApplicationObject(IConstants.SERVICE_FACTORY_KEY);		OrderServiceImpl service = null;		try {			service = factory.createOrderService();		} 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 + -
显示快捷键?