baseaction.java

来自「简单的一个新闻系统。j2ee开发的。对大家学习有帮助。」· Java 代码 · 共 34 行

JAVA
34
字号
package com.org.struts.action;
import javax.servlet.ServletContext;

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

import com.org.spring.service.NewsService;


abstract class BaseAction extends ActionSupport {

    private NewsService newsService;

    public void setServlet(ActionServlet actionServlet) {
        super.setServlet(actionServlet);
        ServletContext servletContext = actionServlet.getServletContext();
        WebApplicationContext wac = WebApplicationContextUtils
                .getRequiredWebApplicationContext(servletContext);

        this.newsService = (NewsService) wac.getBean("newsService");
    }

	public NewsService getNewsService() {
		return newsService;
	}

	public void setNewsService(NewsService newsService) {
		this.newsService = newsService;
	}

}

⌨️ 快捷键说明

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