baseaction.java

来自「SSH经典练习」· Java 代码 · 共 40 行

JAVA
40
字号
package com.ghy.action;

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.ghy.service.CustomerService;


public class BaseAction extends Action{
	private WebApplicationContext wac;
private  CustomerService customerservice;
	
	
	public void setServlet(ActionServlet actionServlet)
	{
		super.setServlet(actionServlet);
		if(actionServlet!=null)
		{
			ServletContext servletContext = actionServlet.getServletContext();
		 wac =	WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
		   this.customerservice=(CustomerService)wac.getBean("customerservice");
		}
		
	}
	protected WebApplicationContext getWebApplicationContext() {
	    return wac;
	  }

	public CustomerService getCustomerservice() {
		return customerservice;
	}

	
}

⌨️ 快捷键说明

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