运行时报错:comp is not bound in this Context

zylhuo 2006-02-23 12:28:51
我在tomcat里配置的数据源,数据驱动是最新下载的。怎么也调不出来。
运行时报错:
javax.servlet.ServletException: Name java:comp is not bound in this Context
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.login_jsp._jspService(login_jsp.java:113)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
请各位高手指点下,谢谢了!!!
...全文
394 点赞 收藏 7
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
infowain 2006-02-23
看看这个
http://www.pconline.com.cn/pcedu/empolder/gj/java/0411/503328.html

建议把数据源配置写在自己的应用的xml里面,这样做简单而且不会有问题。
回复
zylhuo 2006-02-23
大老救命呀!!!还是这样子:
javax.servlet.ServletException: Name java:comp is not bound in this Context
at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
at org.apache.jsp.login_jsp._jspService(login_jsp.java:111)
回复
zylhuo 2006-02-23
老救命呀,还是这样子:
javax.servlet.ServletException: Name java:comp is not bound in this Context
at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
at org.apache.jsp.login_jsp._jspService(login_jsp.java:111)
回复
infowain 2006-02-23
程序

private Connection GetConnection() throws Exception {
Context ctx;
DataSource ds;
Connection conn = null;
String JNDI_NAME="java:comp/env/jdbc/acc";

ctx = new InitialContext();
try {
ds = (DataSource) ctx.lookup(JNDI_NAME);
conn = ds.getConnection();
} catch (Exception E) {
throw new Exception(E.getMessage());
}
return conn;
}

回复
infowain 2006-02-23
给你看看我的
<?xml version='1.0' encoding='utf-8'?>
<Context displayName="Apache-Axis" docBase="Axis" path="/Axis">

<Resource name="jdbc/acc" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/acc">
<parameter>
<name>validationQuery</name>
<value></value>
</parameter>
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>4</value>
</parameter>
<parameter>
<name>password</name>
<value></value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:microsoft:sqlserver://sh-tiger:1433;DatabaseName=accdb</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>2</value>
</parameter>
<parameter>
<name>username</name>
<value>sa</value>
</parameter>
</ResourceParams>

</Context>
回复
zylhuo 2006-02-23
我在javaBean这获取的
try
{
Context initCtx = new javax.naming.InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource)envCtx.lookup("jdbc/ey");
return ds.getConnection();

}
catch(SQLException e)
{
throw e;
}
catch(NamingException e)
{
throw e;
}
以前可以用现在不能用了,老报上面那个错!!!我都快疯了。请帮帮忙。我在网上也找了很多资料,就是没解决~~~~~~~~~~~~~~~~~~~
回复
zylhuo 2006-02-23
老大我看过了:
<Context path="/ELProject" docBase="ELProject" debug="0" reloadable="true" crossContext="true">
<Resource name="jdbc/ey" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/ey">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=EasyDB</value> </parameter>
<parameter>
<name>username</name>
<value>sa</value>
</parameter>
<parameter>
<name>password</name>
<value></value>
</parameter>
<parameter>
<name>maxActive</name>
<value>20</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>10</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>-1</value>
</parameter>
</ResourceParams>
</Context>
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2006-02-23 12:28
社区公告
暂无公告