baseaction.java
来自「java web模拟的简单的一个网络硬盘」· Java 代码 · 共 51 行
JAVA
51 行
package com.dark.nethd.web.action;
import javax.servlet.ServletContext;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionServlet;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.dark.nethd.business.IFilesInfoService;
import com.dark.nethd.business.IUserInfoService;
/*
* 该类拓展了Action类并且作为各个模块的命令类(既Action)的基类,
* 里面的execute方法通过反射机制获得其各个子类中调用的方法名
*/
public class BaseAction extends Action {
private ApplicationContext context = null;
public void setServlet(ActionServlet actionServlet) {
super.setServlet(actionServlet);
ServletContext servletContext = actionServlet.getServletContext();
context = WebApplicationContextUtils
.getRequiredWebApplicationContext(servletContext);
}
protected ApplicationContext getContext() {
return context;
}
protected IUserInfoService userInfoService;
public IUserInfoService getUserInfoService() {
return (IUserInfoService) getContext().getBean("userInfoService");
}
public void setUserInfoService(IUserInfoService userInfoService) {
this.userInfoService = userInfoService;
}
protected IFilesInfoService fliesInfoService;
public IFilesInfoService getFliesInfoService() {
return (IFilesInfoService) getContext().getBean("fliesInfoService");
}
public void setFliesInfoService(IFilesInfoService fliesInfoService) {
this.fliesInfoService = fliesInfoService;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?