`
ynp
  • 浏览: 428632 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

一个简单的ssh配置模板

阅读更多
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">
	<!-- web容器实例化spring实例 -->
	<context-param>
	  <param-name>contextConfigLocation</param-name>
	  <param-value>classpath:beans.xml</param-value>
	</context-param>
	<listener>
	  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	
	<!-- 整合struts -->
	<servlet>
		<servlet-name>struts</servlet-name>
		<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
		<init-param>
			<param-name>config</param-name>
			<param-value>/WEB-INF/struts-config.xml</param-value>
		</init-param>
		<load-on-startup>0</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>struts</servlet-name>
		<url-pattern>*.do</url-pattern>
	</servlet-mapping>
	
	<!-- 处理中文字符乱码问题 -->
	<filter>
	<filter-name>encoding</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>
	<filter-mapping>
		<filter-name>encoding</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	
	<!-- 使用spring解决hibernate因session关闭导致的延迟加载例外问题,即OpenSessionInView -->

	<filter>
	    <filter-name>OpenSessionInViewFilter</filter-name>
	    <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
	</filter>
	<filter-mapping>
        <filter-name>OpenSessionInViewFilter</filter-name>
        <url-pattern>/*</url-pattern>
	</filter-mapping>
		
 	 <welcome-file-list>
    	<welcome-file>index.jsp</welcome-file>
 	 </welcome-file-list>
</web-app>


struts配置------>
<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts-config PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
          "http://struts.apache.org/dtds/struts-config_1_3.dtd">

<struts-config>
	<form-beans>
		<form-bean name="loginForm" type="com.xx.web.form.LoginForm"></form-bean>
	</form-beans>
	<action-mappings>
	
		<action path="/list" type="com.xx.web.action.PersonAction" scope="request" validate="false">
			<forward name="list" path="/WEB-INF/page/list.jsp"/>
		</action>
		<action path="/xx/login" type="com.xx.web.action.LoginAction"  name="loginForm" scope="request" validate="false">
			<forward name="message" path="/WEB-INF/page/message.jsp"/>
		</action>
	</action-mappings>
	<!-- 目的是让spring管理action bean-->
	<controller>
		 <set-property property="processorClass" value="org.springframework.web.struts.DelegatingRequestProcessor"/>
	</controller> 
	
</struts-config>



spring集成Hibernate配置------>
<?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" 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">
	<!-- 数据源配置 -->
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
		<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
		<property name="url" value="jdbc:mysql:///test"/>
		<property name="username" value="root"/>
		<property name="password" value="root"/>
		<!-- 连接池启动时的初始值 -->
		<property name="initialSize" value="1"/>
		<property name="maxActive" value="200"/>
	    <property name="maxIdle" value="5"/>
	    <property name="minIdle" value="2"/>
	</bean>
	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSource"/>
		<!-- hbm.xml文件 -->
		<property name="mappingResources">
			<list>
				<value>com/xx/dao/Person.hbm.xml</value>
			</list>
		</property>
		<!-- Hibernate配置信息 -->
	    <property name="hibernateProperties">
		    <value>
		        hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
		        hibernate.hbm2ddl.auto=update
		        hibernate.show_sql=true
		        hibernate.format_sql=false
		      </value>
        </property>
	</bean>
	<!-- 配置事务信息 -->
	<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  		<property name="sessionFactory" ref="sessionFactory"/>
	</bean>
	<!-- 采用注解方式进行事务配置 -->
	<tx:annotation-driven transaction-manager="txManager"/>
	<!-- 采用注解注入对象 -->
	<context:annotation-config/>
	<bean id="personService" class="com.xx.service.impl.PersonServiceBean"></bean>
	<bean name="/list" class="com.xx.web.action.PersonAction"></bean>
</beans>
分享到:
评论
2 楼 han_yu_han 2011-08-12  
   
能给个qq吗? 我qq 314501792  看到加我啊,哥。
1 楼 009 2011-04-12  
 

相关推荐

Global site tag (gtag.js) - Google Analytics