public class WordProjectinfoAction extends BaseAction implements ServletConfigAware {
private ServletConfig servletconfig;
public void setServletConfig(ServletConfig servletconfig) {
this.servletconfig=servletconfig;

}。
}
这里我实现了 ServletConfigAware    我用的是smartuplad上传  需要初始化servletconfig 
     而我实现了这个接口 怎么报错 说servletconfig 为null  我该则么解决啊 
  谢谢大家

解决方案 »

  1.   

    LZ你实现的是ServletConfigAware 而非servletConfig  如果你实现了servletConfig 那就更不要servletConifg来作为你实现类的属性了对不对 其实就没有根本就没有实现servletConfig  如果你想要这个属性 就要去注入
      

  2.   

    这个不知道怎么解决,但是能不能换一种方式变通地解决,配置信息不一定要在web.xml文件里啊。你把配置放在applicationContext.xml里面不行吗? <util:properties id="myConfig">
    <prop key="someName1">someValue1</prop>
    <prop key="someName2">someValue2</prop>
    </util:properties>
    把myConfig注入到 Action里面去,不也可以吗?
      

  3.   


    看来兄弟你是没有理解 ServletConfigAware 接口的作用啊。
      

  4.   

    简单解释一下。 你在web.xml里面配置东西,无非是想得到一个个的键值对,这么说没错吧。
    <util:properties id="myConfig">
            <prop key="someName1">someValue1</prop>
            <prop key="someName2">someValue2</prop>
        </util:properties>以上定义的就是一个java.util.Properties的bean;名字是“myConfig”。
    下面是一个Action,你不是可以拿到你在配置文件里写的东西了吗?public class SomeAction extends ActionSupport { private java.util.Properties props;      public void execution () {
    // ... String someValue = props.get("someKey");
    } @Resource(name = "myConfig")
    public void setProps(java.util.Properties props) {
    this.props = prps;
    }
    }
      

  5.   


    package com.ncu.hrm.action;import java.util.Map;import javax.servlet.ServletContext;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;import org.apache.struts2.interceptor.ServletRequestAware;
    import org.apache.struts2.interceptor.ServletResponseAware;
    import org.apache.struts2.interceptor.SessionAware;
    import org.springframework.web.context.ServletContextAware;import com.opensymphony.xwork2.ActionContext;
    import com.opensymphony.xwork2.ActionSupport;public class BaseAction extends ActionSupport implements ServletRequestAware, ServletResponseAware, SessionAware, ServletContextAware {
    protected ActionContext actionCtx = ActionContext.getContext(); protected HttpServletRequest request; protected HttpServletResponse response; protected ServletContext application; protected Map<String, Object> session; public void setServletRequest(HttpServletRequest request) {
    this.request = request;
    } public void setServletResponse(HttpServletResponse response) {
    this.response = response; } public void setServletContext(ServletContext application) {
    this.application = application; } public void setSession(Map<String, Object> session) {
    this.session = session; } protected void put(String name, Object value) {
    actionCtx.put(name, value);
    } protected Object get(String name) {
    return actionCtx.get(name);
    }
    }
      

  6.   

    注入?
    ApplicationContent.xml中配置一个bean
    Action中设置一个属性 生成get set就会自动注入了
    或者用@Resource
      

  7.   

    ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(sc);
    adviceManager = (AdviceManager) context.getBean("adviceManager");
    lz 可以读取一下配置文件。。
      

  8.   

    注入不了,那能不能不用注入呀。ServletActionContext应该也行吧