在网上搜了一天了,出现此问题的人很多,我也试了各种解决办法,都不成功,希望大家一起帮我参考下,我觉得可能是配置上的问题。
我在我的META-INF下的context.xml 文件配置如下:
<!-- The contents of this file will be loaded for each web application -->
<Context>
<ResourceLink name="jdbc/modules" global="jdbc/modules" type="javax.sql.DataSource"/>
</Context>
<Resource name="jdbc/modules" auth="Container" type="javax.sql.DataSource"
               maxActive="20" maxIdle="10" maxWait="20000"
               username="root" password="123" driverClassName="com.mysql.jdbc.Driver"
               url="jdbc:mysql://localhost:3306/modules?autoReconnect=true"/></Context>
在WEB-INF下的web.xml文件配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" >
<servlet>
<servlet-name>ObjectServlet</servlet-name>
<servlet-class>modules.servlet.ObjectServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ObjectServlet</servlet-name>
<url-pattern>/obj</url-pattern>
</servlet-mapping>
<description>MySQL Datasource Connection</description>
  <resource-ref>
      <description>DB Connection</description>
      <res-ref-name>jdbc/modules</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
  </resource-ref>
</web-app>
我的连接关键部分代码如下所示:
       Context ctx = new InitialContext();
Context envCtx =  (Context) ctx.lookup("java:comp/env");
 DataSource datasource = (DataSource)envCtx.lookup("jdbc/modules");
 conn =datasource.getConnection();其中我已经把J/Connector 的jar包放在的catalina_base/lib下了
求救各位大侠,小妹我在线等,help!!!!

解决方案 »

  1.   

    有一个地方需要改动的我的context没有设置好,
    标签<context>改为<Context path="/modules" docBase="modules"
            debug="5" reloadable="true" crossContext="true">
    貌似现在没有报错了,汗等我仔细再研究下。也给各位和我有同样困惑的xdjm一个参考。
      

  2.   

    是不是这里要写全的?  <url-pattern>/obj/ObjectServlet</url-pattern> 
      

  3.   

    证明问题已解决,上面的配置方法是可行的,问题真是莫名其妙
    不过呢,有个小提示就是,在写配置文件的时候如果找不到问题,就去tomcat的Doc文档里example的代码
    copy下来,然后再改下配置信息就好了。
    总之问题解决了很开心,很喜欢这个论坛,其实每天都来逛,只是懒得发帖和回帖(好像有点不厚道)
      

  4.   

    tomcat中的几种连接池配置代码(包括tomcat5.0,tomcat5.5x,tomcat6.0) 你应该看看,其实tomcat自己的文档写的很好,不过每个版本都有差异,所以....
      

  5.   

    回zhuye111的话:
    这只是在url下设定的路径而已,随便写什么,只要你在url中与其对应就好了吧。
      

  6.   

    是不是mysql的驱动程序没有放对位置?放在tomcat/shared/lib下。试试