zoukankan      html  css  js  c++  java
  • struts和spring整合

    开发流程:

    1)引jar包,可以在配置工程中设置用户libarary,然后直接引入。如果在web-inf/lib没有用户导入的lib文件,可以参考问题0的解决方案

    需要的是struts_core,spring_core,struts_spring_web

    //struts_core
    Struts2.3.32corecommons-fileupload-1.3.2.jar Struts2.3.32corecommons-io-2.2.jar Struts2.3.32corecommons-lang3-3.2.jar Struts2.3.32corefreemarker-2.3.22.jar Struts2.3.32corejavassist-3.11.0.GA.jar Struts2.3.32coreognl-3.0.19.jar Struts2.3.32corestruts2-core-2.3.32.jar Struts2.3.32corexwork-core-2.3.32.jar
    //spring_core
    spring3.2.9corecommons-logging-1.2.jar spring3.2.9corespring-beans-3.2.9.RELEASE.jar spring3.2.9corespring-context-3.2.9.RELEASE.jar spring3.2.9corespring-core-3.2.9.RELEASE.jar spring3.2.9corespring-expression-3.2.9.RELEASE.jar
    //struts_spring_web
    struts-spring-webstruts2-spring-plugin-2.3.32.jar
    struts-spring-webspring-web-3.2.9.RELEASE.jar
    struts-spring-webspring-webmvc-3.2.9.RELEASE.jar

    2)开发entity/dao/service/action

    3)配置Struts2

    web.xml文件配置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>
    <!-- struts.xml文件    -->
    <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <package name="Userpkg" extends="struts-default" > <action name="save" class="userAction" method="saveUser"> <result name="success">/index.jsp</result> </action> </package> </struts>

    4)配置bean-dao.xml/bean-service.xml/bean-action.xml文件

     <!-- 所有DAO类的配置 -->
            <bean id="userDao" class="com.huitong.Dao.impl.UserDao"></bean>
    <?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"
        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">
            
            <!-- 所有Service类的配置 -->
            <bean id="userService" class="com.huitong.service.impl.UserService">
                <property name="userDao" ref="userDao"></property>
            </bean>
            
    </beans>
    View Code

    bean-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"
        xmlns:p="http://www.springframework.org/schema/p"
        xmlns:context="http://www.springframework.org/schema/context"
        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">
            
            <!-- 所有Action类的配置 -->
            <bean id="userAction" class="com.huitong.action.UserAction">
                <property name="userService" ref="userService"></property>
            </bean>
            
    </beans>
    View Code

    5)在web.xml文件中配置spring

    <!-- 2 配置spring -->
        <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/classes/bean-*.xml</param-value>
        </context-param>
    
        <listener>
         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>

    最后可以测试了,应该是可以通过的

    struts2.3.32,spring3.2.9进行整合,

    出现问题0:MyEclipse 使用 User Library 不自动部署到 WEB-INF/lib 

    在项目上右键进入Properties,选择Deployment Assembly,再点击Add...,如下图所示:

    2.然后在弹出的窗口中,选择Java Build Path Entries,点击Next,如下图所示:



    3.选择你要你引入的UserLibrary,点击Finish即可

    出现问题1:java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet

    解决办法:导包,spring-webmvc-3.2.9.RELEASE.jar

  • 相关阅读:
    将单向链表按某值划分为左边小、中间相等、右边大的形式
    数组中的数字按某值划分为左边小、中间相等、右边大的形式
    Kendo UI for jQuery管理数据有妙招!轻松将数据存储为JSON
    DevExpress Xamarin.Forms v21.1
    界面控件Telerik UI for WinForm初级教程
    WPF应用程序的主题颜色如何修改?DevExpress调色板工具很好用
    DevExpress WinForm模板库可快速创建Windows样式的应用程序界面
    Kendo UI for jQuery数据管理使用教程:Spreadsheet
    开发框架DevExtreme入门级教程
    跨平台.NET应用程序界面开发新亮点
  • 原文地址:https://www.cnblogs.com/zhaopengcheng/p/6786341.html
Copyright © 2011-2022 走看看