<jsp:useBean id="global" class="xxxxx" scope="application" />

解决方案 »

  1.   

    getServletContext().setAttribute("attrubute",object);
      

  2.   

    就是说getServletContext().setAttribute
    就可以设置全局变量?在web.xml中或者某个配置文件中不能设置吗?
      

  3.   

    <jsp:useBean id="aaa" class="bbb" scope="application" />
     或用单例模式
      

  4.   

    Re: 在web.xml中或者某个配置文件中不能设置吗?
    在web.xml加上以下代码 <context-param>
    <param-name>form_repository_path</param-name>
    <param-value>e:/form</param-value>
    <description></description>
    </context-param>
      

  5.   

    <context-param>
    <param-name>变量的名称</param-name>
    <param-value>设置的变量的值</param-value>
    <description>要调用这个变量,需要调用方法 getServletContext(),该方法返回一个对隐式声明的 application 变量的引用。
    </description>
    </context-param>