to zxhong(红透半边天):我后来又试了一步直接查找的,也可以了,没有先查找环境设置,在通过初始化环境设置的context去找xxx/xxx...看来我的问题就是出在包的存放位置和.jar还是zip上了.....
我原来 也放到过 web-inf/lib下 好像不行,后来放到 common/lib就可以了
为什么会这样呢,兄台 lib directory. All the JAR/zip files used by the web application, including the third-party JAR/zip files, go in this directory. For example, if a servlet uses JDBC to connect to a database, the JDBC driver JAR file should go here. We can also package the servlet classes in a JAR file and keep that file in this directory. At runtime, the servlet container adds all the JAR/zip files from this directory to the classpath for this web application.(摘自某刊物^-^)
---》
String dbName ="java:/comp/env";Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource)envCtx.lookup("jdbc/Oracle");
//分2步,不是一步到位的!
请参考:
http://expert.csdn.net/Expert/topic/1190/1190848.xml?temp=.5132868
根据你的异常信息很清楚地看到 你的 驱动程序 不能正确加载
sandyen(杉叶)所说的是正确的方法
另外一步应该是可以的
1.可直接改写没有meta-inf的信息,还能读,那不就是没分别了嘛,是支持的压缩包就可以。我会试试别的。
2.为什么放在examples/的web-inf/lib下就读不出来驱动呢??
lib directory. All the JAR/zip files used by the web application, including the
third-party JAR/zip files, go in this directory. For example, if a servlet uses JDBC
to connect to a database, the JDBC driver JAR file should go here. We can also
package the servlet classes in a JAR file and keep that file in this directory. At
runtime, the servlet container adds all the JAR/zip files from this directory to
the classpath for this web application.(摘自某刊物^-^)
我想可以理解是这样的
你配置jndi的web.xml是服务器用的,这样的一般都要放到 common/lib
而自己用的 就可以用 web-inf/lib
而common/lib下是WEB服务器起来的时候就需要加载的