Java Web整合开发(78) -- Struts 1

Struts1.3数据源配置详解

在Struts1.3中已经取消了<data-sources>标签,也就是说只能在1.2版中配置,因为Apache不推荐在 struts-config.xml中配置数据源。所以建议不要在struts中配置数据源,如果你用了hibernate或spring得话就可以在 hibernate配置文件或spring文件配数据源如果都没用就到tomcat中配置

tomcat数据源配置
1.在$CATALINA_HOME/conf/context.xml中添加配置信息,声明连接池的具体信息,添加内容如下:

<Resource name="jdbc/mysql" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdel="30" maxWait="10000" username="root" password="mysql" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/struts?characterEncoding=UTF-8" />

 

2. 在应用程序(webapplication)的web.xml的</web-app>前添加如下信息:

<!-- 引用tomcat中配置的数据源 -->
<resource-ref> <description>struts connection</description> <res-ref-name>jdbc/mysql</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>

配置以上内容后,只要在你的Jsp或Javabean 中按以下方式创建连接,就可以

(JNDI)

// Obtain our environment naming context
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");

// Look up our data source DataSource ds = (DataSource)envCtx.lookup("jdbc/mysql"); // Allocate and use a connection from the pool Connection conn = ds.getConnection();

 

struts-config.xml配置文件详解  

http://blog.youkuaiyun.com/huozhicheng/article/details/5426356

转载于:https://www.cnblogs.com/thlzhf/p/4383644.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值