getServletContext().getAttribute("driver")

解决方案 »

  1.   

    不行也!getServletContext().getAttribute("driver")取出来null值!
      

  2.   

    你要在你的SERVER.XML中<Context标记中加上crossContext="true"然后才能调用getServletContext().getAttribute("driver")
      

  3.   

    我在我的server.xml中加入这样的context
     <Context path="/web1" docBase="d:/myweb" debug="0" reloadable="true" crossContext="true"> 
            </Context>
    对吗?如果没问题的话,那为什么取出来还是null值呢?
      

  4.   

    不用crossContext,那个是干别的用的。应该用getServerConfig().getInitParameter("driver")。如果用getServerContext().getInitParameter("driver"),则driver需要在<context-param>中定义。
      

  5.   

    猫兄:
    是在web.xml中这样设置吗?
    <web-app>
       <context-param>driver</context-param>
       <contextvalue>com.microsoft.jdbc.sqlserver.SQLServerDriver
       </context-value>
     </web-app>,如果这样设置没错的话,但是在启动tomact时会报错呢?
    猫兄,希望你进一步支持小弟
      

  6.   

    <web-app>
      <context-param>
        <param-name>driver</param-name>
        <param-value>com.microsoft.jdbc.sqlserver.SQLServerDriver</param-value>
      </context-param>
      ...
    </web-app>