bos01_ssh框架的搭建

1.  导入jar包

  1. 我们的项目需要整合SSH,所以需要导入SSH、Spring依赖、日志、数据库驱动、数据库池等jar包
  •      导入Struts2的jar
  1. 访问http://struts.apache.org/downloads.html下载Struts框架,这里下载2.3.32版本
  2. 导入\struts-2.3.32\apps\struts2-blank\WEB-INF\lib目录下的所有jar包到项目
  3. 导入struts与spring整合的插件jar包,
  4. 目录为\struts-2.3.32-all\struts-2.3.32\lib\struts2-spring-plugin-2.3.32

2. 导入Spring的jar包

  1. 访问https://repo.spring.io/webapp/#/search/archive/网站,搜索相关版本的spring-framework下载
  2. 或者访问http://repo.spring.io/release/org/springframework/spring/

           a):  下载spring-framework-3.2.0.RC2-docs

           b):  下载spring-framework-3.2.0.RC2-dist

  • 导入spring的核心包

3.  导入spring的依赖包

  1. com.springsource.com.mchange.v2.c3p0-0.9.1.2.jar
  2. com.springsource.org.aopalliance-1.0.0Log4j.jar
  3. com.springsource.org.apache.log4j-1.2.15.jar
  4. com.springsource.org.apache.commons.logging-1.1.1.jar
  5. com.springsource.org.aspectj.weaver-1.6.8.RELEASE
  • 导入Hibernater的包

1.导入hibernate3.jar

2.导入\hibernate-distribution-3.6.10.Final\lib\required里的所有jar包

3.导入hibernate-jpa-2.0-api-1.0.1.Final.jar

4. cglib-2.2.jar不用导,因为spring的核心包里已经集成了cglib

5.数据库驱动包

6.hibernater的日志包是【slf4j 】- 【slf4j-log4j12-1.7.2】- 【log4j-前面spring导入了】

7.javassist包导重了,删除一个

8.把项目中Web App Libraries删除,自己再把lib的jar包build到path中,方便可以删除一个jar包IEDA不用管这步骤

2.  配置

  • web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

    <!-- 1.加载spring配置文件-->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:beans.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!--2.配置字符编码的过滤器-->
    <filter>
        <filter-name>characterEncodingFilter</filter-name>
        <!--spring-web包提供的CharacterEncodingFilter只能解决POST的中文乱码问题-->
        <!--<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>-->
        <filter-class>com.gyf.bos.web.filter.MyEncodingFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>characterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!-- 3.配置struts的拦截器-->
    <filter>
        <filter-name>strut2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>strut2</filter-name>
        <url-pattern>/*</url-pattern>
        <!--请求和转发都会被strut2拦截
            默认情况下,只有请求会被拦截
        -->
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>
</web-app>
  • struts

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

    <package name="p1" extends="struts-default">
        <!-- 配置jsp页面的访问规则-->
        <action name="page_*_*" >
            <result name="success">/WEB-INF/pages/{1}/{2}.jsp</result>
        </action>

        <action name="test" class="com.gyf.bos.web.action.TestAction" method="test">
            <result name="success">page_user_list</result>
        </action>
    </package>
</struts>

 

猜你喜欢

转载自blog.csdn.net/qq_26594041/article/details/88082834