zoukankan      html  css  js  c++  java
  • SSH框架

    1.WEB-INF下  web.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/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
    <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>
    <filter>
    <filter-name>struts</filter-name>
    <filter-class>
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    </filter-class>
    </filter>
    <filter-mapping>
    <filter-name>struts</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>REQUEST</dispatcher>
    </filter-mapping>

    <resource-ref>
    <res-ref-name>jdbc/cmis</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>

    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    </web-app>

    2.struts.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

    <struts>

    <!-- 开发模式的热启动 -->
    <constant name="struts.devMode" value="true" />

    <!-- 将struts action的对象交给spring来处理 -->
    <constant name="struts.objectFactory" value="spring"></constant>

    <package name="user" namespace="/name" extends="struts-default">
    <action name="userAction_*" class="userAction" method="{1}">

    //根据返回值配置跳转页面

    <result>
    /userlist.jsp
    </result>
    </action>

    </package>

    </struts>

    3.Applicationcontext-common.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: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-3.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">


    <bean id="myDataSource"
    class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName"
    value="com.mysql.jdbc.Driver">
    </property>
    <property name="url" value="jdbc:mysql://localhost:3306/mdym"></property>
    <property name="username" value="root"></property>
    <property name="password" value="chang"></property>
    </bean>


    <bean id="mySessionFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource">
    <ref bean="myDataSource" />
    </property>
    <property name="hibernateProperties">
    <value>
    hibernate.dialect=org.hibernate.dialect.MySQLDialect
    hibernate.show_sql=true
    hibernate.format_sql=false
    hibernate.cache.use_second_level_cache=true hibernate.cache.use_query_cache=false hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
    </value>
    </property>

    <property name="annotatedClasses">
    <list>
    <value>com.test.model.Student</value>
    </list>
    </property>
    </bean>


    <!-- spring管理对象 -->
    <bean id="txManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="myDataSource"></property>
    </bean>

    <!-- 声明事务对象处理 -->
    <tx:advice id="txAdvice" transaction-manager="txManager">
    <tx:attributes>
    <tx:method name="add*" propagation="REQUIRED" />
    <tx:method name="select*" propagation="REQUIRED" />
    <tx:method name="update*" propagation="REQUIRED" />
    <tx:method name="delete*" propagation="REQUIRED" />
    <tx:method name="*" propagation="REQUIRED"/>
    </tx:attributes>
    </tx:advice>

    <!-- 把事务加入所有的service层处理 -->
    <aop:config>
    <aop:pointcut id="allserviceMethod"
    expression="execution(* com.test.service.*.*(..))"/>
    <!-- 把声明的事务和切点 allserviceMethod装配到一起 -->
    <aop:advisor pointcut-ref="allserviceMethod" advice-ref="txAdvice"/>
    </aop:config>

    <bean id="userDao" class="com.test.dao.impl.UserDaoImpl">
    <property name="SessionFactory" ref="mySessionFactory"></property>
    </bean>

    <bean id="userService" class="com.test.service.UserService">
    <property name="userDao" ref="userDao"></property>
    </bean>

    </beans>

    4.Applicationcontext-action.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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <!-- 切记 scope="prototype"不能省略 -->
    <bean id="userAction" class="com.test.action.UserAction">
    <property name="userService" ref="userService"></property>
    </bean>
    </beans>

  • 相关阅读:
    Palindrome Partitioning
    Minimum Path Sum
    Maximum Depth of Binary Tree
    Minimum Depth of Binary Tree
    Unique Binary Search Trees II
    Unique Binary Search Trees
    Merge Intervals
    Merge Sorted Array
    Unique Paths II
    C++ Primer Plus 笔记第九章
  • 原文地址:https://www.cnblogs.com/ssrsblogs/p/2974557.html
Copyright © 2011-2022 走看看