SSH框架的配置文件
struts 配置文件 struts.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <include file="struts-default.xml"/> <constant name="struts.devMode" value="true" /> <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.custom.i18n.resources" value="globalMessages" /> <constant name="struts.objectFactory" value="spring" /> <constant name="struts.ui.theme" value="css_xhtml" /> <constant name="struts.multipart.maxSize" value="1000000" /> <constant name="struts.url.includeParams" value="none" /> <constant name="struts.action.extension" value="do" /> <package name="default" extends="struts-default" namespace="/"> <interceptors> <interceptor-stack name="testStack"> <interceptor-ref name="defaultStack"></interceptor-ref> </interceptor-stack> </interceptors> <default-interceptor-ref name="testStack"></default-interceptor-ref> <action name="checkuser" class="lcz.test.java2excel.action.OutputAction" method="checkuser"> <result name="success">WEB-INF/pages/checkuser.jsp</result> <result name="input">WEB-INF/pages/wrongpwd.jsp</result> </action> </package> </struts>
jdbc配置 jdbc.properties
jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/virtualexam?useUnicode=true&EncodingCharacter=utf8 jdbc.username=root jdbc.password=1234 hibernate.dialect=org.hibernate.dialect.MySQLDialect hibernate.show_sql=true hibernate.cache.use_query_cache=true hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider hibernate.default_batch_fetch_size=50 hibernate.jdbc.fetch_size=50 hibernate.jdbc.batch_size=50
日志文件的配置 log4j.properties
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE}%5p %c{1}:%L - %m%n
log4j.rootLogger=INFO, stdout
log4j.logger.org.hibernate=INFO
log4j.logger.org.hibernate.type=INFO
log4j.logger.java.sql.Connection=debug
log4j.logger.java.sql.PreparedStatement=debug
log4j.logger.java.sql.ResultSet=debug
hibernate 配置文件 Student.hbm.xml
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="lcz.test.java2excel.bean.Student" table="t_student" > <id name="studentId" type="integer"> <column name="student_id" /> <generator class="increment" /> </id> <property name="studentName" type="string"> <column name="student_name" length="50" not-null="true" /> </property> <property name="studentPassword" type="string"> <column name="student_password" length="50" not-null="true" /> </property> <property name="studentRealName" type="string"> <column name="student_real_name" length="50" not-null="true" /> </property> </class> </hibernate-mapping>
spring配置文件 applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:flex="http://www.springframework.org/schema/flex" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <context:property-placeholder location="classpath:jdbc.properties"/> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass"><value>${jdbc.driverClassName}</value></property> <property name="jdbcUrl"><value>${jdbc.url}</value></property> <property name="user"><value>${jdbc.username}</value></property> <property name="password"><value>${jdbc.password}</value></property> <property name="minPoolSize"><value>10</value></property> <property name="maxPoolSize"><value>100</value></property> <property name="maxIdleTime"><value>1800</value></property> <property name="acquireIncrement"><value>2</value></property> <property name="maxStatements"><value>0</value></property> <property name="initialPoolSize"><value>10</value></property> <property name="idleConnectionTestPeriod"><value>1000</value></property> <property name="acquireRetryAttempts"><value>30</value></property> <property name="acquireRetryDelay"><value>100</value></property> <property name="breakAfterAcquireFailure"><value>false</value></property> <property name="testConnectionOnCheckout"><value>false</value></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <!-- class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> --> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:hibernate.cfg.xml" /> <property name="mappingResources"> <list> <value>Student.hbm.xml</value> <value>Admin.hbm.xml</value> <value>Category.hbm.xml</value> <value>Question.hbm.xml</value> <value>Score.hbm.xml</value> <value>Teacher.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop> <prop key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop> <prop key="hibernate.default_batch_fetch_size">${hibernate.default_batch_fetch_size}</prop> <prop key="hibernate.jdbc.fetch_size">${hibernate.jdbc.fetch_size}</prop> <prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop> <prop key="hibernate.format_sql">false</prop> </props> </property> </bean> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!-- dao注入 --> <bean id="studentDao" class="lcz.test.java2excel.dao.impl.StudentDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- service注入 --> <bean id="computeStudentService" class="lcz.test.java2excel.service.impl.ComputeStudentServiceImpl"> <property name="studentDao" ref="studentDao"></property> </bean> <!-- action注入 --> <bean id="OutputAction" class="lcz.test.java2excel.action.OutputAction" scope="prototype"> <property name="computeStudentService" ref="computeStudentService"></property> </bean> </beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>VirtualExam</display-name> <listener> <!--ContextLoaderListener的作用就是启动Web容器时,自动装配ApplicationContext的配置信息 --> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/classes/applicationContext.xml,classpath:applicationContext-*.xml</param-value> </context-param> <filter> <filter-name>struts-cleanup</filter-name> <!--for upload file --> <filter-class> org.apache.struts2.dispatcher.ActionContextCleanUp </filter-class> </filter> <filter-mapping> <filter-name>struts-cleanup</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>struts2</filter-name> <!-- struts配置文件 --> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> <init-param> <param-name>config</param-name> <param-value> struts.xml,struts-default.xml,struts-plugin.xml </param-value> </init-param> </filter> <filter-mapping> <!--截取struts的所有url --> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
注:
1.web.xml内各个配置节点的加载顺序与它们在 web.xml 文件中的先后顺序无关。即不会因为 filter 写在 listener 的前面而会先加载 filter
真正的加载顺序为:context-param -> listener -> filter -> servlet
2. 对于某类配置节而言,与它们出现的顺序是有关的。
filter 拦截资源是按照 filter-mapping 配置节出现的顺序来依次调用 doFilter() 方法的。