日期:2014-05-18  浏览次数:20702 次

Tomcat6.0抛出 name jdbc is not found in this Context
在网上搜了一天了,出现此问题的人很多,我也试了各种解决办法,都不成功,希望大家一起帮我参考下,我觉得可能是配置上的问题。
我在我的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!!!!


------解决方案--------------------
是不是这里要写全的? <url-pattern>/obj/ObjectServlet</url-pattern>
------解决方案--------------------
tomcat中的几种连接池配置代码(包括tomcat5.0,tomcat5.5x,tomcat6.0)

你应该看看,其实tomcat自己的文档写的很好,不过每个版本都有差异,所以....
------解决方案--------------------
问题解决就好了,哈哈。
------解决方案--------------------
是不是mysql的驱动程序没有放对位置?

放在tomcat/shared/lib下。试试