您的位置:首页 > 其它

从零开始学习SSH框架笔记之四 几个关键配置文件备忘(模板)

2013-07-22 09:43 567 查看
不多说,直接上代码。关于注释我尽量写详细点。

1、web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!-- ********************struts2******************** -->
<!-- struts2的过滤器 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<!-- 配置struts2的配置文件路径
<init-param>
<param-name>config</param-name>
<param-value>
struts.xml
</param-value>
</init-param>
-->
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<!-- ********************spring******************** -->
<!-- 配置spring的监听器,用以实现依赖注射 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- 配置spring的配置文件的读取路径 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>

<!-- 配置spring的缓存清除监听器,可选 -->
<listener>
<listener-class>
org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>

<!-- 配置设置spring框架编码的过滤器,可选 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>

<!-- ********************hibernate******************** -->
<!-- 配置hibernate的过滤器
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
-->

<!-- 配置映射路径
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
-->

<!-- ********************other******************** -->
<!-- 配置session超时的时间 -->
<session-config>
<session-timeout>40</session-timeout>
</session-config>

<!-- 配置欢迎页面 -->
<display-name>AGUI</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>


2、applicationContext.xml(放置spring的配置文件,包括hibernate的配置文件)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC
"-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<import resource="classpath:database.xml" />

<bean id="userDao" class="com.ssh.daoimpl.UserDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>

<bean id="userService" class="com.ssh.serviceimpl.UserServiceImpl">
<property name="userDao" ref="userDao"></property>
</bean>

<bean id="regAction" class="com.ssh.action.RegAction">
<property name="userService" ref="userService"></property>
</bean>

<bean id="listUserAction" class="com.ssh.action.ListUserAction">
<property name="userService" ref="userService"></property>
</bean>

<bean id="deleteUserAction" class="com.ssh.action.DeleteUserAction">
<property name="userService" ref="userService"></property>
</bean>
</beans>


3、database.xml(放置spring的配置文件,包括hibernate的配置文件)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC
"-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="configBean"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:dataSource.properties</value>
</property>
</bean>

<!--C3P0 数据源-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<!-- 指定连接数据库的驱动 -->
<property name="driverClass" value="${dataSource.driverClassName}"/>
<!-- 指定连接数据库的URL -->
<property name="jdbcUrl" value="${dataSource.url}"/>
<!-- 指定连接数据库的用户名 -->
<property name="user" value="${dataSource.username}"/>
<!-- 指定连接数据库的密码 -->
<property name="password" value="${dataSource.password}"/>
<!-- 指定连接数据库连接池的最大连接数 -->
<property name="maxPoolSize" value="500"/>
<!-- 指定连接数据库连接池的最小连接数 -->
<property name="minPoolSize" value="10"/>
<!-- 指定连接数据库连接池的初始化连接数 -->
<property name="initialPoolSize" value="5"/>
<!-- 指定连接数据库连接池的连接的最大空闲时间 -->
<property name="maxIdleTime" value="60"/>
<!--JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量. 如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0-->
<property name="maxStatements" value="0"/>
<!-- 在当前连接数耗尽的时候,一次获取的新的连接数    -->
<property name="acquireIncrement" value="3"/>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${dataSource.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/ssh/bean/user.hbm.xml</value>
</list>
</property>
</bean>

<!-- 事务管理器(拦截器) -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

</beans>


4、dataSource.properties(保存数据库的连接信息)

dataSource.driverClassName=oracle.jdbc.driver.OracleDriver
dataSource.url=jdbc:oracle:thin:@ZHUNIAN-THINK:1521:XE
dataSource.username=zhunian
dataSource.password=密码
dataSource.dialect=org.hibernate.dialect.OracleDialect


5、struts.xml(放置struts的配置文件)

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="user" extends="struts-default">
<action name="RegAction" class="regAction">
<result name="success">/list.jsp</result>
<result name="input">/save.jsp</result>
</action>
<action name="ListUserAction" class="listUserAction">
<result name="success">/list.jsp</result>
<result name="input">/index.jsp</result>
</action>
<action name="DeleteUserAction" class="deleteUserAction">
<result name="success">/list.jsp</result>
<result name="input">/index.jsp</result>
</action>
</package>
</struts>


http://www.uspcat.com/?fromuid=11777
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: