Struts.xml配置文件
- XML code
<?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> <constant name="struts.custom.i18n.resources" value="globalResource" /> <package name="TestSSH" extends="json-default"> <interceptors> <!-- interceptors拦截器 --> <interceptor name="authorization" class="interceptor.AuthorizationInterceptor" /> <interceptor-stack name="myStack"> <interceptor-ref name="authorization"> <param name="ignoreActions"> validate_code,register.*,.*login.* </param> </interceptor-ref> <interceptor-ref name="defaultStack" /> </interceptor-stack> </interceptors> <default-interceptor-ref name="myStack" /> <global-results> <result name="success">/WEB-INF/jsp/result_json.jsp</result> <result name="error">/WEB-INF/jsp/result_json.jsp</result> <result name="login" type="redirectAction">login_page</result> </global-results> <!-- LoginAction类的配置 --> <action name="login" class="action.LoginAction"> <result name="success">main_page.action</result> <result name="input">/WEB-INF/jsp/login.jsp</result> </action> <action name="*_jsp"> <result>/META-INF/jsp/{1}.jsp</result> </action> <!-- RegisterAction类的配置 --> <action name="register" class="action.RegisterAction"> <result name="success">/WEB-INF/jsp/result.jsp</result> <result name="input">/WEB-INF/jsp/register.jsp</result> </action> <!-- CreateDirAction配置文件 --> <action name="crateDir" class="action.CreateDirAction"> <result name="success">/WEB-INF/jsp/create_dir_result.jsp</result> </action> <!-- UploadAction配置文件 --> <action name="upload" class="action.UploadAction"> <result name="success">/WEB-INF/jsp/upload_success.jsp</result> </action> <!-- DownloadFileAction配置文件 --> <action name="downloadFile" class="action.DownloadFileAction"></action> <!-- DownloadMoreFileAction配置文件 --> <action name="downloadMoreFile" class="action.DownloadMoreFileAction"></action> </package> </struts>
applicationContext.xml配置
- XML code
<?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:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <!-- 指定hibernate的配置文件 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation" value="classpath:hibernate.cfg.xml"> </property> </bean> <!-- 装配Hibernate对象 --> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <!-- 装配事务管理对象 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref bean="sessionFactory"/> </property> </bean> <!-- 装配事务拦截器 --> <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <property name="transactionManager"> <!-- 为transactionManager指定事务管理对象 --> <ref bean="transactionManager"/> </property> <property name="transactionAttributes"> <!-- 设置事务属性 --> <props> <prop key="get*">PROPAGATION_REQURID, readOnly</prop> <prop key="getDirInfo">PROPAGATION_REQUIRED</prop> <prop key="*">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- 通过Bean名自动代理数据访问层对象 --> <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <!-- 指定需要代码类的实现的接口 --> <property name="beanNames"> <list> <value>useDAO</value> <value>directoryDAO</value> <value>fileDAO</value> </list> </property> <property name="interceptorNames"> <list> <value>transactionInterceptor</value> </list> </property> </bean> <!-- 下面的代码装配数据库访问层 --> <!-- 装配UserDAOImpl类 --> <bean id="userDao" class="dao.UserDAOImpl"> <constructor-arg> <ref bean="hibernateTemplate"/> </constructor-arg> </bean> <!-- 装配DirectoryDAOImpl类 --> <bean id="directoryDAO" class="dao.DirectoryDAOImpl"> <constructor-arg> <ref bean="hibernateTemplate"/> </constructor-arg> </bean> <!-- 装配FileDAOImpl类 --> <bean id="fileDAO" class="dao.FileDAOImpl"> <constructor-arg> <ref bean="hibernateTemplate"/> </constructor-arg> </bean> <!-- 下面的代码装配业务逻辑访问层 --> <!-- 装配UserServiceImpl类 --> <bean id="userService" class="service.UserServiceImpl"> <constructor-arg> <ref bean="userDAO"/> </constructor-arg> </bean> <!-- 装配DirectoryDAOImpl类 --> <bean id="directoryService" class="service.DirectoryServiceImpl"> <constructor-arg> <ref bean="directoryDAO"/> </constructor-arg> <constructor-arg> <ref bean="fileDAO"/> </constructor-arg> </bean> <!-- 装配FileServiceImpl类 --> <bean id="fileService" class="service.FileServiceImpl"> <constructor-arg> <ref bean="fileDAO"/> </constructor-arg> </bean> <!-- 装配ServiceManage类 --> <bean id="serviceManage" class="service.ServiceManage"> <property name="userService"> <!-- 装配userService属性 --> <ref bean="userService"/> </property> <property name="directoryService"> <!-- 装配directoryService属性 --> <ref bean="directoryService"/> </property> <property name="fileService"> <!-- 装配fileService属性 --> <ref bean="fileService"/> </property> </bean> <!-- 指定外部的资源文件,在该文件中配置网络硬盘的根目录 --> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"> <value>WEB-INF\TestSSH.properties</value> </property> </bean> <bean id="userInfo" class="common.UserInfo" scope="prototype"> <property name="root" value="${TestSSH.root"></property> </bean> </beans>