SSH框架的搭建_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > SSH框架的搭建

SSH框架的搭建

 2013/8/18 21:28:48  l391639272  程序员俱乐部  我要评论(0)
  • 摘要:选择jar包struts2解压apps文件夹下的struts2-blank,选择里面lib文件夹下所有的jar包和相关lib下的包asm.jarasm-commons.jarasm-tree.jarcommons-fileupload.jarcommons-io.jarcommons-lang.jarcommons-logging.jarfreemarker.jarjavassist-3.11.0.GA.jarlog4j.jarognl.jarstruts2-convention-plugin
  • 标签:SSH

选择jar包

struts2

解压apps文件夹下的struts2-blank,选择里面lib文件夹下所有的jar包和相关lib下的包

asm.jar

asm-commons.jar

asm-tree.jar

commons-fileupload.jar

commons-io.jar

commons-lang.jar

commons-logging.jar

freemarker.jar

javassist-3.11.0.GA.jar

log4j.jar

ognl.jar

struts2-convention-plugin.jar

struts2-core.jar

xwork-core.jar

?

相关lib下的struts2jar包

commons-beanutils.jar

commons-collections.jar

aoplliance.jar

?

hibernate

lib下的required下的所有的jar包,optional下的c3p0下的jar包,jpa下的jar包

?

spring

spring-aop.jar

spring-aspects.jar

sprng-beans.jar

spring-context.jar

spring-core.jar

spring-expression.jar

spring-jdbc.jar

spring-orm.jar

spring-tx.jar

spring-web.jar

?

外加的包

aspectjweaver.jar

mysql-connector-java-bin.jar

dom4j.jar

slf4j-api.jar

slf4j-log4j.jar

?

配置web.xml文件

class="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/j2ee" xmlns:javaee="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/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_9" version="2.4">
  <!-- spring监听器 -->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  
   <context-param>
  <param-name>contextConfigLocation</param-name> 
  <param-value>classpath:applicationContext.xml</param-value> 
  </context-param>
  
  <!-- openSessionInView配置 -->
	<filter>
		<filter-name>openSessionInViewFilter</filter-name>
		<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
		<init-param>
			<param-name>singleSession</param-name>
			<param-value>true</param-value>
		</init-param>

<init-param>  
<param-name>sessionFactoryBeanName</param-name>  
<param-value>sessionFactory</param-value>  
</init-param>   
</filter> 
 
<filter-mapping>  
<filter-name>openSessionInViewFilter</filter-name>  
<url-pattern>/*</url-pattern>  
</filter-mapping>
	
  <!-- Struts2配置 -->
<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>register.jsp</welcome-file>
  </welcome-file-list>
  
  <!--编码问题 -->
	<filter>
		<filter-name>encodingFilter</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>
		<init-param>   
            <param-name>forceEncoding</param-name>   
            <param-value>true</param-value>   
        </init-param> 
	</filter>
	<filter-mapping>
		<filter-name>encodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
</web-app>

?

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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/aop
         http://www.springframework.org/schema/aop/spring-aop.xsd
         http://www.springframework.org/schema/tx
         http://www.springframework.org/schema/tx/spring-tx.xsd
         "
 default-autowire="byName">
			
	<!--凡是要注解的对象都在com.jyjsf这个包下找-->
	<context:annotation-config />
	<context:component-scan base-package="com.ynaidi" />
	
	<!-- —————————————————————————————————————————————————— -->
	<!-- 使用SpringAOP管理Hibernate中的Transaction——声明式事务管理 -->
	<!-- —————————————————————————————————————————————————— -->

	<!-- 声明数据源头 -->
	<bean id="dataSourceBean" 
		class="org.springframework.jdbc.datasource.DriverManagerDataSource">
		<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
		<property name="url" value="jdbc:mysql://localhost:3306/ssh"/>
		<property name="username" value="root"/>
		<property name="password" value="123"/>
	</bean>

	
	<!-- 声明由Spring提供的Hibernate SessionFactory -->	
	<bean id="sessionFactory" 
		class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
		scope="singleton">
		<property name="configLocation" value="classpath:hibernate.cfg.xml"/>
		<property name="dataSource" ref="dataSourceBean"/>
		<property name="packagesToScan" value="com.ynaidi.model" /> 
	</bean>
	  <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
	<!-- 声明由Spring提供的Hibernate事务管理器——就是一个切面Bean -->
	<bean id="txManagerBean"
		class="org.springframework.orm.hibernate4.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory"/>
	</bean>
	
	<!-- 将上述的txManagerBean声明为AOP中的切面 -->
	<aop:config>
		<aop:pointcut id="allModelMethod" expression="execution(* com.jyjsf.service.*.*(..))" />
		<!-- 使用advisor代替aspect -->
		<aop:advisor advice-ref="txManagerAdvice" pointcut-ref="allModelMethod"/>
	</aop:config>
	
	<!-- 声明管理事务的advice——无需指定执行方法,只需要指定事务管理器即可 -->
	<tx:advice id="txManagerAdvice" transaction-manager="txManagerBean">
		<tx:attributes>
			 <tx:method name="exists" read-only="true" />  
        <tx:method name="save*" propagation="REQUIRED" />    
       <tx:method name="add*" propagation="REQUIRED" />    
        <tx:method name="create*" propagation="REQUIRED" />    
        <tx:method name="insert*" propagation="REQUIRED" />    
        <tx:method name="update*" propagation="REQUIRED" />    
        <tx:method name="merge*" propagation="REQUIRED" />    
        <tx:method name="del*" propagation="REQUIRED" />    
        <tx:method name="remove*" propagation="REQUIRED" />    
        <tx:method name="put*" propagation="REQUIRED" />    
        <tx:method name="use*" propagation="REQUIRED"/>    
        <!-- hibernate4必须配置为开启事务 否则 getCurrentSession()获取不到    --> 
        <tx:method name="get*" propagation="REQUIRED" />    
        <tx:method name="count*" propagation="REQUIRED" read-only="true" />    
        <tx:method name="find*" propagation="REQUIRED" read-only="true" />    
        <tx:method name="list*" propagation="REQUIRED" read-only="true" />   
         <tx:method name="*" propagation="REQUIRED" />  
		</tx:attributes>
	</tx:advice>
	
	<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
        <property name="scopes">
            <map>
                <entry key="session">
                    <bean class="org.springframework.web.context.request.SessionScope" />
                </entry>
                <entry key="request">
                    <bean class="org.springframework.web.context.request.RequestScope" />
                </entry>
            </map>
        </property>
    </bean>
	
	
</beans>

?

hibernate.cfg.xml

<!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="dialect">org.hibernate.dialect.MySQLDialect</property>
		<property name="show_sql">true</property>
		<property name="format_sql">true</property>
		<property name="hbm2ddl.auto">update</property>
	</session-factory>
</hibernate-configuration>

?

?

struts.xml

<?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.enable.DynamicMethodInvocation" value="true" />
    <constant name="struts.devMode" value="false" />
    <constant name="struts.ui.theme" value="simple" />
    <!-- 允许上传的最大数据 -->
    <constant name="struts.multipart.maxSize" value="10737418240"/>
    <!-- 报错异常的中文转译 -->
    <constant name="struts.custom.i18n.resources" value="uploadmessage"></constant>
    
<!--     定义全局package -->
  <package name="defaultpackage" extends="struts-default">
    <interceptors>
   <interceptor-stack name="defStack">
    <interceptor-ref name="defaultStack"></interceptor-ref>
    <interceptor-ref name="sessionNull"></interceptor-ref>
   </interceptor-stack>
   <interceptor name="sessionNull" class="com.jyjsf.interceptor.SessionNullInterceptor" />
  </interceptors>
  <default-interceptor-ref name="defStack" />
  
  <global-results>
                 <result name="sessionnull">
                       /login.jsp
                 </result>    
            </global-results>
  
 </package>
 
</struts>

?SSH目录树结构如附件图

?

  • 大小: 33 KB
  • 查看图片附件
发表评论
用户名: 匿名