SSH简单整合总结,个人新手,精通出门左转

22 篇文章 0 订阅
10 篇文章 0 订阅
Struts2
1.struts2的配置文件,CLASS路径写Spring配置的bean

Hibernate在整合方面
1.表之间的映射文件
2.基本的hibernate配置,方言,url,driveclass,root,password

Spring在整合方面应该做的事:
1.配置一个适合的数据源
2.配置一个session factory,然后把数据源和hibernate的配置文件和映射文件配进去
3.配置事务,把session factory 配置个事务管理器,然后再配置切面属性

4.处理action的分配,设置scope的配置属性为prototype(非单例)


接下来帖下我的代码,看上面总结写的重点即可,其他忽略不计

Struts2

<span style="font-size:18px;color:#ff0000;"><?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
	"http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
	 
	<constant name="struts.action.extension" value="action,do,"></constant>

	<package name="library" extends="struts-default" namespace="/">
	
	
		<interceptors>
			<interceptor name="easyDeal" class="com.zhku.Spring.Hibernate.Action.ExceptionDeal.EasyDealExcptionUtil"></interceptor>
			<interceptor name="loginFliter" class="com.zhku.Spring.Hibernate.Action.ExceptionDeal.loginFilter"></interceptor>
			
			<interceptor-stack name="myInterceptorStack">
				<interceptor-ref name="paramsPrepareParamsStack"></interceptor-ref>
				<interceptor-ref name="cookie">
					<param name="cookiesName">*</param>
					<param name="cookiesValue">*</param>
				</interceptor-ref>
				<interceptor-ref name="easyDeal"></interceptor-ref>
			</interceptor-stack>
			<interceptor-stack name="filterStack">
				<interceptor-ref name="loginFliter"></interceptor-ref>
				<interceptor-ref name="paramsPrepareParamsStack"></interceptor-ref>
			</interceptor-stack>
			
		</interceptors>
		
		<default-interceptor-ref name="myInterceptorStack"></default-interceptor-ref>
		
		<global-results>
                    <result name="error">/error/error.jsp</result>
        </global-results>
        
        <global-exception-mappings>
                    <exception-mapping result="error" exception="java.lang.RuntimeException"></exception-mapping>
        </global-exception-mappings>
		
		
		<action name="managerLoginAction" class="managerLoginActionBean">
			<result>/HT/ht.jsp</result>
		</action>	
		
		<action name="*Book" class="bookActionBean" method="{1}">
			<interceptor-ref name="filterStack"></interceptor-ref>
			<result>/HT/preBookHtml.jsp</result>			
			<result name="{1}">/HT/{1}BookHtml.jsp</result>			
		</action>
		
		<action name="deleteBook2" class="bookActionBean" method="delete">
			<interceptor-ref name="filterStack"></interceptor-ref>
			<result name="delete" type="redirectAction">
				<param name="actionName">allBook</param>
				<param name="firstResult">0</param>
				<param name="MaxResult">12</param>
			</result>
		</action>
			
		
		
		<action name="*Other" class="otherActionBean" method="{1}">
			<result>/success.jsp</result>
			<result name="{1}">/QT/{1}BookHtml.jsp</result>
		</action>
		
		<action name="getPic" class="getPicActionBean">
			<result type="stream"></result>
		</action>
		
		
		<action name="*register" class="registerActionBean" method="{1}">
			<result name="invalid.token" type="redirect">/QT/register/register.jsp</result>
			<result name="input">/QT/register/register.jsp</result>
			<result name="{1}">/QT/register/login.jsp</result>
		</action>
		
		<action name="yzm" class="yzmActionBean">
			<result type="stream"></result>
		</action>
		
		<action name="user*" class="userActionBean" method="{1}">
			<result name="{1}">/QT/register/user{1}Html.jsp</result>
		</action>
		
		
		<action name="userLogin" class="userActionBean">
		
			<result name="input" type="redirect">/QT/register/login.jsp</result>
			<result>/QT/brand.jsp</result>
		</action>
		
		<action name="reBookBorrow" class="bbActionBean">
		<interceptor-ref name="filterStack"></interceptor-ref>
			<result>/HT/re.html</result>
		</action>
		
		<action name="*Borrow" class="bbActionBean" method="{1}">
		<interceptor-ref name="filterStack"></interceptor-ref>
			<result name="{1}">/HT/{1}BorrowBookHtml.jsp</result>
		</action>
		
		<action name="sendMail" class="mailActionBean" method="send">
		<interceptor-ref name="filterStack"></interceptor-ref>
			<result name="send">/HT/deleteBorrowBookHtml.jsp</result>
		</action>
		
		<action name="*Mail" class="mailActionBean" method="{1}">
			<interceptor-ref name="filterStack"></interceptor-ref>
			<result name="{1}">/QT/getMail.jsp</result>
		</action>
	</package>
	
</struts></span>
hibernate
<span style="font-size:18px;color:#333399;"><!DOCTYPE hibernate-configuration PUBLIC
	"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
	"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
	<session-factory>
		<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
		<property name="javax.persistence.validation.mode">none</property>			
		<property name="hibernate.hbm2ddl.auto">update</property>	
		<property name="show_sql">false</property>
		<property name="format_sql">false</property>
	</session-factory>
</hibernate-configuration></span>
<span style="font-size:18px;color:#333399;">
</span>
<span style="font-size:48px;color:#333399;">Spring</span>
<span style="font-size:18px;color:#333399;">
</span>
<?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:context="http://www.springframework.org/schema/context"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:aop="http://www.springframework.org/schema/aop"    
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
		 http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
		">
	
		<!-- 导入资源文件 -->
	<context:property-placeholder location="classpath:db.properties"/>
	<context:component-scan base-package="com.zhku.Spring.Hibernate"></context:component-scan>
	
	 
	<bean id="book" class="com.zhku.Spring.Hibernate.entites.Book"></bean>
	<bean id="bookBorrowInformation" class="com.zhku.Spring.Hibernate.entites.BookBorrowInformation"></bean>
	<bean id="manager" class="com.zhku.Spring.Hibernate.entites.Manager"></bean>
	<bean id="student" class="com.zhku.Spring.Hibernate.entites.Student"></bean>
	<bean id="mail" class="com.zhku.Spring.Hibernate.entites.Mail"></bean>
	
	<!-- 利用註解配置action,指定名稱和scope -->
	
	<bean id="managerLoginActionBean" class="com.zhku.Spring.Hibernate.Action.ManagerLoginAction" scope="prototype"></bean>	
	<bean id="bookActionBean" class="com.zhku.Spring.Hibernate.Action.BookAction" scope="prototype"></bean>
	<bean id="otherActionBean" class="com.zhku.Spring.Hibernate.Action.otherAction" scope="prototype"></bean>
	<bean id="getPicActionBean" class="com.zhku.Spring.Hibernate.Action.getPic" scope="prototype"></bean>
	<bean id="registerActionBean" class="com.zhku.Spring.Hibernate.Action.registerAction" scope="prototype"></bean>
	<bean id="yzmActionBean" class="com.zhku.Spring.Hibernate.Action.YZM" scope="prototype"></bean>	
	<bean id="userActionBean" class="com.zhku.Spring.Hibernate.Action.UserAction" scope="prototype"></bean>	
	<bean id="bbActionBean" class="com.zhku.Spring.Hibernate.Action.BookBorrowAction" scope="prototype"></bean>
	<bean id="mailActionBean" class="com.zhku.Spring.Hibernate.Action.MailAction" scope="prototype"></bean>
	
	
	
	<!-- 配置 C3P0 数据源 -->
	<bean id="dataSource"
		class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="user" value="${user}"></property>
		<property name="password" value="${password}"></property>
		<property name="jdbcUrl" value="${url}"></property>
		<property name="driverClass" value="${driverClass}"></property>

		<property name="initialPoolSize" value="${initPoolSize}"></property>
		<property name="maxPoolSize" value="${maxPoolSize}"></property>
	</bean>
	<!-- 配置session工厂 -->
	<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
	<!-- 导入数据源 -->
		<property name="dataSource" ref="dataSource"></property>
	<!-- 加载hibernate配置 -->
		<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
	<!-- 加载hbm文件配置 -->
		<property name="mappingLocations"
			value="classpath:com/zhku/Spring/Hibernate/entites/*.hbm.xml"
		></property>
	</bean>

	

	<!-- 配置事务管理器 -->
	<bean id="dataSourceTransactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	
	<!-- 配置事务属性 -->
	<tx:advice transaction-manager="dataSourceTransactionManager" id="ad">
		<tx:attributes>	
			<tx:method name="get*" read-only="true"/>
			<tx:method name="*"/>
		</tx:attributes>
	</tx:advice>
	<!-- 配置事务切入点 -->
	<aop:config>
		<aop:pointcut expression="execution(* com.zhku.Spring.Hibernate.Service.*.*(..))" id="pt"/>
		<aop:advisor advice-ref="ad" pointcut-ref="pt"/>
	</aop:config> 
	
</beans>

关于上传到服务器上时对tomcat的修改,个人比较喜欢直接访问域名访问到根目录项目

修改server.xml

所以把tomcat的端口号改为80,并且在<host/>添加一个context节点配置





  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值