SSH+Oracle框架搭建总结

1.创建一个名为01ssh的web项目
2.导入必要的jar包(对于导入jar包,包含..\struts2\struts-2.3.4\apps\struts2-blank\WEB-INF\lib下的全部,还有..\hibernate4\source-hibernate-release-4.3.10.Final\hibernate-release-4.3.10.Final\lib\required下的jar包,这一步记得去掉与struts2中的重复jar包,还有..\spring4\source\spring-framework-4.1.6.RELEASE\libs下的一部分jar包,另外还需要antlr-2.7.7.jar,
aopalliance-1.0.jar,commons-logging-1.1.1.jar,aspectjweaver.jar,struts2-spring-plugin-2.3.4.jar)
jar包列表:

    antlr-2.7.7.jar
    aopalliance-1.0.jar
    asm-3.3.jar
    asm-commons-3.3.jar
    asm-tree-3.3.jar
    aspectjweaver.jar
    commons-fileupload-1.2.2.jar
    commons-io-2.0.1.jar
    commons-lang3-3.1.jar
    commons-logging-1.1.1.jar
    dom4j-1.6.1.jar
    freemarker-2.3.19.jar
    hibernate-commons-annotations-4.0.5.Final.jar
    hibernate-core-4.3.10.Final.jar
    hibernate-jpa-2.1-api-1.0.0.Final.jar
    jandex-1.1.0.Final.jar
    javassist-3.11.0.GA.jar
    jboss-logging-3.1.3.GA.jar
    jboss-logging-annotations-1.2.0.Beta1.jar
    jboss-transaction-api_1.2_spec-1.0.0.Final.jar
    ognl-3.0.5.jar
    ojdbc6.jar
    spring-aop-4.1.6.RELEASE.jar
    spring-aspects-4.1.6.RELEASE.jar
    spring-beans-4.1.6.RELEASE.jar
    spring-context-4.1.6.RELEASE.jar
    spring-core-4.1.6.RELEASE.jar
    spring-expression-4.1.6.RELEASE.jar
    spring-jdbc-4.1.6.RELEASE.jar
    spring-orm-4.1.6.RELEASE.jar
    spring-test-4.1.6.RELEASE.jar
    spring-tx-4.1.6.RELEASE.jar
    spring-web-4.1.6.RELEASE.jar
    struts2-core-2.3.4.jar
    struts2-spring-plugin-2.3.4.jar
    xwork-core-2.3.4.jar    
3.  编写web.xml,struts.xml,application-dao.xml文件

web.xml配置


<web-app id="WebApp_9" 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">


  <context-param>
    <param-name>contextConfigLocationparam-name>
    <param-value>classpath:applicationContext-*.xmlparam-value>
  context-param>

 
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>

  
  <filter>
    <filter-name>osivfilter-name>
    <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilterfilter-class>
  filter>
  <filter-mapping>
    <filter-name>osivfilter-name>
    <url-pattern>*.actionurl-pattern>
  filter-mapping>


    <filter>
        <filter-name>struts2filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilterfilter-class>
    filter>

    <filter-mapping>
        <filter-name>struts2filter-name>
        <url-pattern>/*url-pattern>
    filter-mapping>

    <welcome-file-list>
        <welcome-file>index.htmlwelcome-file>
    welcome-file-list>
web-app>

struts.xml配置




<struts>
    <package name="default" namespace="/" extends="struts-default">
        <action name="list" class="userAction" method="list">
            <result name="success">/index.jspresult>
        action>
    package>
struts>

application-dao.xml配置


<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:context="http://www.springframework.org/schema/context"
    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.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">
    
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
        <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl"/>
        <property name="username" value="scott"/>
        <property name="password" value="tiger"/>
    bean>
    
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource">property>
        
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialectprop>
                <prop key="hibernate.show_sql">trueprop>
                <prop key="hibernate.format_sql">trueprop>
            props>
        property>
        
        <property name="annotatedClasses">
            <array>
                <value>com.swy.vo.Uservalue>
            array>
        property>
    bean>
    
    
    <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory">property>
    bean>
    
    <tx:advice id="txAdvice" transaction-manager="txManager">
    <tx:attributes>
        
        <tx:method name="save*" propagation="REQUIRED"/>
        <tx:method name="update*" propagation="REQUIRED"/>
        <tx:method name="find*" read-only="true"/>
        <tx:method name="*" propagation="REQUIRED"/>
    tx:attributes>
  tx:advice>
  <tx:annotation-driven transaction-manager="txManager"/>
    
    <aop:config>
        <aop:pointcut expression="execution(* com.swy.service.impl.*.*(..))" id="pointcut"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut"/>
    aop:config>
    
    <context:component-scan base-package="com.swy">context:component-scan>

beans>

4.编写action类

@Controller
@Scope("prototype")
public class UserAction {
    //此处仅用作环境搭建成功测试使用
    public String list(){
            System.out.println("这里是action");
            return Action.SUCCESS;
        }
}

然后,如果成功,根据struts.xml配置,会跳转至index.jsp页面
5.启动服务

6.测试
在浏览器输入http://localhost:8080/01ssh/list.action
注意:01ssh表示项目名
如果成功,则跳至index.jsp页面
7.项目结构
SSH+Oracle框架搭建总结_第1张图片

你可能感兴趣的:(SSH框架整合)