tomcat 5.5.9 与之前的版本的配置方法不同
1.现在%tomcat home%/conf/catalina/localhost 下面添加一段独立的context xml段,命名为jasper.xml,例如<?xml version="1.0" encoding="UTF-8"?>
<Context path="/jasper" docBase="jasper" debug="1" reloadable="true" crossContext="true">
</Context>2.通过admin的界面(或手动在server.xml界面里进行配置)数据源,以sql2k为例,配置后的server.xml应该为<?xml version="1.0" encoding="UTF-8"?>
<Server>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
<GlobalNamingResources>
<Environment
name="simpleValue"
type="java.lang.Integer"
value="30"/>
<Resource
auth="Container"
description="User database that can be updated and saved"
name="UserDatabase"
type="org.apache.catalina.UserDatabase"
pathname="conf/tomcat-users.xml"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"/>
<Resource
name="jdbc/Northwind"
type="javax.sql.DataSource"
password="*****"
driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
maxIdle="2"
maxWait="5000"
username="sa"
url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Northwind"
maxActive="20"/>
</GlobalNamingResources>
<Service
name="Catalina">
<Connector
port="80"
redirectPort="8443"
minSpareThreads="25"
connectionTimeout="20000"
maxSpareThreads="75"
maxThreads="150"
maxHttpHeaderSize="8192">
</Connector>
<Connector
port="8009"
redirectPort="8443"
protocol="AJP/1.3">
</Connector>
<Engine
defaultHost="localhost"
name="Catalina">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
<Host
appBase="webapps"
name="localhost">
</Host>
</Engine>
</Service>
</Server>3.在conf下面的context.xml文件中,</Context>之前加入 <ResourceLink name="jdbc/Northwind" global="jdbc/Northwind" type="javax.sql.DataSourcer"/>4.在你的web文件夹下面的WEB-INF中找到web.xml,在最后</web-app>之前加入<resource-ref>
<description>Northwind Connection</description>
<res-ref-name>jdbc/Northwind</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>5.保存,重启tomcat,这样,通过测试页面,就可以发现已经可以通过数据库连接池连上sql2ktest1.jsp<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@page import="javax.naming.*"%>
<%@page import="javax.sql.*"%>
<%
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/Northwind");
Connection conn = ds.getConnection();
int counts=0;
String sql="select count(*) from orders";
PreparedStatement pst=conn.prepareStatement(sql);
ResultSet rst=pst.executeQuery();
while(rst.next()){
counts=rst.getInt(1);
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>JNDI 测试</title>
</head><body>
<%=sql%><br>
pnrreg talbe's count is:<%=counts%>
</body>
</html>
1.现在%tomcat home%/conf/catalina/localhost 下面添加一段独立的context xml段,命名为jasper.xml,例如<?xml version="1.0" encoding="UTF-8"?>
<Context path="/jasper" docBase="jasper" debug="1" reloadable="true" crossContext="true">
</Context>2.通过admin的界面(或手动在server.xml界面里进行配置)数据源,以sql2k为例,配置后的server.xml应该为<?xml version="1.0" encoding="UTF-8"?>
<Server>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
<GlobalNamingResources>
<Environment
name="simpleValue"
type="java.lang.Integer"
value="30"/>
<Resource
auth="Container"
description="User database that can be updated and saved"
name="UserDatabase"
type="org.apache.catalina.UserDatabase"
pathname="conf/tomcat-users.xml"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"/>
<Resource
name="jdbc/Northwind"
type="javax.sql.DataSource"
password="*****"
driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
maxIdle="2"
maxWait="5000"
username="sa"
url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Northwind"
maxActive="20"/>
</GlobalNamingResources>
<Service
name="Catalina">
<Connector
port="80"
redirectPort="8443"
minSpareThreads="25"
connectionTimeout="20000"
maxSpareThreads="75"
maxThreads="150"
maxHttpHeaderSize="8192">
</Connector>
<Connector
port="8009"
redirectPort="8443"
protocol="AJP/1.3">
</Connector>
<Engine
defaultHost="localhost"
name="Catalina">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
<Host
appBase="webapps"
name="localhost">
</Host>
</Engine>
</Service>
</Server>3.在conf下面的context.xml文件中,</Context>之前加入 <ResourceLink name="jdbc/Northwind" global="jdbc/Northwind" type="javax.sql.DataSourcer"/>4.在你的web文件夹下面的WEB-INF中找到web.xml,在最后</web-app>之前加入<resource-ref>
<description>Northwind Connection</description>
<res-ref-name>jdbc/Northwind</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>5.保存,重启tomcat,这样,通过测试页面,就可以发现已经可以通过数据库连接池连上sql2ktest1.jsp<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@page import="javax.naming.*"%>
<%@page import="javax.sql.*"%>
<%
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/Northwind");
Connection conn = ds.getConnection();
int counts=0;
String sql="select count(*) from orders";
PreparedStatement pst=conn.prepareStatement(sql);
ResultSet rst=pst.executeQuery();
while(rst.next()){
counts=rst.getInt(1);
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>JNDI 测试</title>
</head><body>
<%=sql%><br>
pnrreg talbe's count is:<%=counts%>
</body>
</html>
解决方案 »
- webservice初学,在调用的时候出错
- 怎么window.showModalDialog返回值一直为空
- 关于Struts2.0寻找DTD的问题
- 如何通过JS实现动态上传附件
- 网页上的图片放在目录中和数据库字段中各有什么优缺点?
- 简单问题:session有效期的设定。
- 急!急!急!!!在线等待,高分奉送
- Undefined variable or class name: out,这个out.println是写在一个函数里面的!!!请教怎么改?
- jbuilder包导入的问题
- 关于hibernate 对于每个实体的配置问题!
- 请问高手,如果装reisn-3.0.13与IIS 6(有多个站点)整合起来啊??
- 有关java发邮件
这样做的错误还是一样啊
是加一个jasper.xml, 其中加一段 <context ></context>
是jasper.xml ,如果没有的话就新建一个
在jasper.xml文件中包含:
<context>
....
....
....
....
</context>
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/jasper" docBase="jasper" debug="1" reloadable="true" crossContext="true"></Context>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>5.5已经不需要这个了只要把dbcp放在common/lib下就可以了删掉这段
还不如自己写一个读取xml的文件,xml文件里保存好连接串呢
各位以为如何