在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.csdn.net/huozhicheng/article/details/5426356

posted on 2015-04-01 13:46  逝者如斯(乎)  阅读(139)  评论(0编辑  收藏  举报