📄 netstoredispatchaction.java
字号:
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.DispatchAction;
public class NetstoreDispatchAction extends DispatchAction {
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -