context.xml配置如下:
<Resource name="db/myutil"
auth="Container"
type="com.newer.db.DBConnection"
factory="org.apache.naming.factory.BeanFactory"
/>
web.xml配置如下:
<resource-ref>
<res-ref-name>db/myutil</res-ref-name>
<res-type>com.newer.db.DBConnection</res-type>
<res-auth>Container</res-auth>
</resource-ref>
jsp页面代码如下:
<%
Context ctx = new InitialContext();
DBConnection db = (DBConnection)ctx.lookup("java:comp/env/db/myutil");
System.out.println(db);
%>
打开JSP页面,有异常:
javax.naming.NamingException: Cannot create resource instance
错误代码指向:DBConnection db = (DBConnection)ctx.lookup("java:comp/env/db/myutil");