码迷,mamicode.com
首页 > 编程语言 > 详细

Spring(四):Spring整合Hibernate,之后整合Struts2

时间:2017-05-09 17:40:43      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:code   log   final   package   extends   lis   .com   容器   sof   

  • 背景:

  上一篇文章《Spring(三):Spring整合Hibernate》已经介绍使用spring-framework-4.3.8.RELEASE与hibernate-release-5.2.9.Final项目整合搭建的过程,本文基于上一篇文章的基础之上,整合Struts2。

  开发环境简介:

    1)、jdk 1.8

    2)、spring-framework-4.3.8.RELEASE、hibernate-release-5.2.9.Final、struts-2.3.31

  • 引入Struts2的jar开发包到新建项目My-SSH中

  将\struts-2.3.31-all\struts-2.3.31\apps\struts2-blank.war文件解压,之后将struts-2.3.31-all\struts-2.3.31\apps\struts2-blank\WEB-INF\lib\下的所有jar发布包拷贝到My-SSH项目的WebContent\WEB-INF\lib\下。

技术分享

之后,需要查看是否My-SSH项目的WebContent\WEB-INF\lib\中的jar包是否有重复的jar包,如果有重复的jar包,需要删除版本低的jar包(否则,会发生版本冲突)。

技术分享

  • 在My-SSH项目的WebContent\WEB-INF\web.xml中添加filter

  从\struts-2.3.31-all\struts-2.3.31\apps\struts2-blank\WEB-INF\web.xml中可以找到struts2的filter配置信息,并把filter配置信息拷贝到My-SSH项目的WebContent\WEB-INF\web.xml中,

技术分享

配置之后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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID"
    version="3.0">
    <display-name>My-SSH</display-name>
    
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index</welcome-file>
    </welcome-file-list>
    
    <!-- 配置启动IOC容器的Listener -->
    <!-- needed for ContextLoaderListener -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>

    <!-- Bootstraps the root web application context before servlet initialization -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    
    <!-- Struts2 filter -->    
    <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>
    
</web-app>
  • 将struts2的配置文件struts.xml拷贝到My-SSH项目的conf下

  将\struts-2.3.31-all\struts-2.3.31\apps\struts2-blank\WEB-INF\classes\struts.xml文件拷贝到My-SSH项目的conf下,技术分享

并编辑为如下内容:

<?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="false" />
    <constant name="struts.devMode" value="true" />

    <package name="default" namespace="/" extends="struts-default">

    </package>
</struts>

 

Spring(四):Spring整合Hibernate,之后整合Struts2

标签:code   log   final   package   extends   lis   .com   容器   sof   

原文地址:http://www.cnblogs.com/yy3b2007com/p/6831538.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!