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


    在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

  • 相关阅读:
    js取当前时间的秒级时间戳
    微信自动聊天脚本
    小程序 缓存过期问题
    去掉表格默认样式
    css3 画心
    数据导入(二):MapReduce
    数据导入(一):Hive On HBase
    HBase参数优化
    Hadoop运维手记
    HBase优化相关
  • 原文地址:https://www.cnblogs.com/thlzhf/p/4383644.html
Copyright © 2020-2023  润新知