struts2怎么获取web.xml文件中<context-param>的值struts2

解决方案 »

  1.   

    ServletContext sc=this.getServletContext();
    String name=sc.getInitParameter("<param-name>对应的name");
      

  2.   


    我说的是在Action中怎么获取,我写的类只是实现了Action ,是不是要实现其它的接口,按你这样取不到啊!!报空指针了!
      

  3.   

    ServletActionContext.getServletContext().getInitParameter("ur-param-name");
      

  4.   


    我说的是在Action中怎么获取,我写的类只是实现了Action ,是不是要实现其它的接口,按你这样取不到啊!!报空指针了!基本都用ActionSupport的。
    public class MyActionImpl extends ActionSupport implements MyAction
    ActionSupport已经实现了Action 直接就可以继承 而且也不用必须提供execute方法了。
      

  5.   

    另外,ServletActionContext是struts2提供的专门用于访问原始Servlet的一个工具类。
      

  6.   

    getServletConfig().getServletContext().getInitParameter("name");