在网上搜了一天了,出现此问题的人很多,我也试了各种解决办法,都不成功,希望大家一起帮我参考下,我觉得可能是配置上的问题。
我在我的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!!!!
我在我的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!!!!
解决方案 »
- 【求助】Ext控件模拟触屏录音对讲功能
- 新手求教程?
- java关于split分割字符串问题,请教高手!
- Hibernate一次查询,执行N条sql语句,跪求解决方法
- 急!!!!在添加记录的时候,总是提示错误插入ID是空,JSP中应该是自动获取ID的吧?
- 我是菜鸟,问个菜鸟问题。。。setProperty
- 请问jarkarta/POI/HSSF生成的EXCEL文件如何通过JSP或Servlet输出到客户端并保存??
- 一个想和大家探讨的问题(来着有分,不够可以在加)
- jsp与javascript的区别???
- 请问JavaBean可以调用了另外一个JavaBean的方法吗?
- 一个关于SSH的系统错误!
- 在打开网页时,不做任何操作,就想看到从数据库是中调出来的数据,怎样实现?
标签<context>改为<Context path="/modules" docBase="modules"
debug="5" reloadable="true" crossContext="true">
貌似现在没有报错了,汗等我仔细再研究下。也给各位和我有同样困惑的xdjm一个参考。
不过呢,有个小提示就是,在写配置文件的时候如果找不到问题,就去tomcat的Doc文档里example的代码
copy下来,然后再改下配置信息就好了。
总之问题解决了很开心,很喜欢这个论坛,其实每天都来逛,只是懒得发帖和回帖(好像有点不厚道)
这只是在url下设定的路径而已,随便写什么,只要你在url中与其对应就好了吧。