baseaction.java

来自「struts+hibernate+spring框架实现」· Java 代码 · 共 31 行

JAVA
31
字号
package com.cvicse.myssh.struts.action.base;

import javax.servlet.ServletContext;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionServlet;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.cvicse.myssh.spring.service.ILoginService;

//不用加Listener时可以用这种方法获取配置文件及配置文件中的属性
public class BaseAction extends Action {

	private ILoginService iloginService;
	
	public void setServlet(ActionServlet actionServlet) {
		super.setServlet(actionServlet);
		ServletContext servletContext = actionServlet.getServletContext();
		WebApplicationContext wac =
			WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
		System.out.println(wac);
		this.iloginService = (ILoginService) wac.getBean("loginManager");
	}

	public ILoginService getIloginService() {
		return iloginService;
	}

}

⌨️ 快捷键说明

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