S2SH中文件配置的步骤

Spring

     在WEB-INF目录下,添加配置文件 applicationContext.xml

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

<beans>
<!-- action -->
	<bean id="loginAction" class="action.LoginAction">
		<property name="clGysDao" ref="clGysDao"></property>
		<property name="clGrzxxDao" ref="clGrzxxDao"></property>
		<property name="clZxcmxDao" ref="clZxcmxDao" ></property>
		<property name="clGgzxcDao" ref="clGgzxcDao"></property>	
		<property name="clCzDao" ref="clCzDao"></property>	
	</bean>
	<bean id="clgysAction" class="action.ClGysAction">
		<property name="clGysDao" ref="clGysDao"></property>
	</bean>
	<bean id="clGrzxxAction" class="action.ClGrzxxAction">
		<property name="clGrzxxDao" ref="clGrzxxDao"></property>
		<property name="clClgrmxDao" ref="clClgrmxDao"></property>
		<property name="ywYwlsDao" ref="ywYwlsDao"></property>
		<property name="clGgzxcDao" ref="clGgzxcDao"></property>
	</bean>
	<bean id="xcrzAction" class="action.XcrzAction">
		<property name="clCzDao" ref="clCzDao"></property>
		<property name="clGgzxcDao" ref="clGgzxcDao"></property>
		<property name="ywYwlsDao" ref="ywYwlsDao"></property>
		<property name="clCldpmxDao" ref="clCldpmxDao"></property>
	</bean>
	<bean id="clczAction" class="action.ClCzAction">
		<property name="clCzDao" ref="clCzDao"></property>
	</bean>
	<bean id="xxcxAction" class="action.XxcxAction">
		<property name="clCdDao" ref="clCdDao"></property>
		<property name="clCzDao" ref="clCzDao"></property>
	</bean>
<!-- dao -->
	<bean id="clCdDao" class="dao.ClCdDao">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<bean id="clCldpmxDao" class="dao.ClCldpmxDao">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<bean id="clCzDao" class="dao.ClCzDao">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<bean id="clGgzxcDao" class="dao.ClGgzxcDao">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<bean id="ywYwlsDao" class="dao.YwYwlsDao">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<bean id="clZxcmxDao" class="dao.ClZxcmxDao">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<bean id="clClgrmxDao" class="dao.ClClgrmxDao">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<bean id="clGysDao" class="dao.ClGysDao">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<bean id="clGrzxxDao" class="dao.ClGrzxxDao">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>

<!--xxxxxxxxxxxxxxxxxxxxxxxxxxx  -->
	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
	</bean>
	
	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	
	<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
		<property name="transactionAttributes">
			<props>
				<prop key="save*">PROPAGATION_REQUIRED</prop>
				<prop key="update*">PROPAGATION_REQUIRED</prop>
				<prop key="delete*">PROPAGATION_REQUIRED</prop>
				<prop key="*">readOnly</prop>
			</props>
		</property>
		<property name="transactionManager" ref="transactionManager"></property>
	</bean>
	<bean id="autoproxy" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
		<property name="beanNames" value="*Dao"></property>
		<property name="interceptorNames" value="transactionInterceptor"></property>
		<!-- 对类的代理 -->
		<property name="proxyTargetClass" value="true"></property>		
	</bean>
</beans>

在src目录下:

创建 hibernate.cfg.xml 文件

 Hibernate 一般采取制动生成 hibernate.cfg.xml 与 model.hbm.xml 映射文件

 

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration>

	<session-factory>
		<property name="connection.username">scott</property>
		<property name="connection.url">
			jdbc:oracle:thin:@localhost:1521:orcl
		</property>
		<property name="dialect">
			org.hibernate.dialect.Oracle9Dialect
		</property>
		<property name="myeclipse.connection.profile">oracle</property>
		<property name="connection.password">tiger</property>
		<property name="connection.driver_class">
			oracle.jdbc.driver.OracleDriver
		</property>
		<property name="show_sql">true</property>
		<property name="current_session_context_class">thread</property>
		<property name="hbm2ddl.auto">update</property>

		<mapping resource="model/ClGys.hbm.xml" />
		<mapping resource="model/ClGrzxx.hbm.xml" />
		<mapping resource="model/ClClgrmx.hbm.xml" />
		<mapping resource="model/ClZxcmx.hbm.xml" />
		<mapping resource="model/YwYwls.hbm.xml" />
		<mapping resource="model/ClGgzxc.hbm.xml" />
		<mapping resource="model/ClCz.hbm.xml" />
		<mapping resource="model/ClCd.hbm.xml" />
		<mapping resource="model/ClCldpmx.hbm.xml" />
		<mapping resource="model/ClCdxx.hbm.xml" />

	</session-factory>

</hibernate-configuration>
 

 

Struts 2.1.8 

创建Struts.xml action 中的class 为

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
    "http://struts.apache.org/dtds/struts-2.1.7.dtd">
<struts>
	<!-- 在开发模式下使用,这样可以打印出更详细的错误信息 -->     
    <constant name="struts.devMode" value="true" /> 
	
	<package name="bike" namespace="/" extends="struts-default">
		<action name="login" class="loginAction">
			<result name="index">/main/index.htm</result>
		</action>
		<action name="clgys" class="clgysAction">
			<result name="clgys">/main/gztm/clgys.jsp</result>
			<result name="xgclgys">/main/gztm/xgclgys.jsp</result>
			<result name="invalid.token">/main/index.htm</result>
		</action>
		<action name="clgrzxx" class="clGrzxxAction">
			<result name="zjclgrzxx">/main/gztm/zjclgrzxx.jsp</result>
			<result name="clgrzxx">/main/gztm/clgrzxx.jsp</result>
			<result name="clgrmx">/main/gztm/clgrmx.jsp</result>
			
			<!--  token拦截器已经系统定义,所以不用再次定义,一定不能把默认的覆盖掉,也要配上. --> 
	 		<!--  token这个Interceptor没有默认配到拦截器栈中 --> 
	 		<!--  
	  		<interceptor-ref name="token" /> 
	 	 	<interceptor-ref name="defaultStack" /> 
	 	 	-->
			<!--  重复提交跳转的页面 -->  
	 		<!--  这个拦截器需要有一个返回页面,返回值:固定,struts2给定  --> 
			<!--  一般解决重复提交解决办法:1.提交完redirect.2.用这个拦截器 --> 
	  <!--  <result name="invalid.token">/main/index.htm</result>-->
		</action>
		<action name="xcrz" class="xcrzAction">
			<result name="xcrz">/main/gztm/xcrz.jsp</result>
			<result name="chezhuang">/main/gztm/chezhuang.jsp</result>
		</action>
		<action name="clcz" class="clczAction">
			<result name="chezhuang">/main/gztm/chezhuang.jsp</result>
		</action>
		<action name="xxcx" class="xxcxAction">
			<result name="xxcx">/main/gztm/xxcx.jsp</result>
			<result name="viewCdxx">/main/gztm/viewCdxx.jsp</result>
			<result name="viewZxcxx">/main/gztm/viewZxcxx.jsp</result>
		</action>
	</package>
</struts>

 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 
	xmlns="http://java.sun.com/xml/ns/j2ee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
	http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	<!-- 
	 -->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
	</filter>
	<filter-mapping>
		<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>

  Action 中

    ActionContext ac = ActionContext.getContext();
    HttpServletRequest request =(HttpServletRequest) ac.get(ServletActionContext.HTTP_REQUEST);

 

你可能感兴趣的:(spring,Hibernate,struts,s2sh)