美文网首页
Spring 框架第二天 ssd整合 ssh分开整合

Spring 框架第二天 ssd整合 ssh分开整合

作者: 三招六式一把铁斧 | 来源:发表于2017-07-27 22:03 被阅读0次

    一、ssd整合(spring+struts+jdbc)

    步骤:
    1. 导入入struts+spring整合需要的jar文件(struts2-spring-plugin-2.3.1.2)
    2. 配置web.xml
      (1)
    Paste_Image.png Paste_Image.png

    (2)
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    1. 配置 spring文件
    Paste_Image.png

    源码:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" 
        xmlns="http://java.sun.com/xml/ns/javaee" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
        <!-- 配置struts -->
      <filter>
        <filter-name>struts2</filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
        </filter-class>
      <!-- struts.xml如在src根目录下不用配置,不在则做如下配置 -->
      <init-param>
      <!-- config名不能改 -->
      <param-name>config</param-name>
      <param-value>struts-default.xml,struts-plugin.xml,config/struts.xml</param-value>
      </init-param>
      </filter>
      <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>
      <!-- 配置spring ,整合struts时如果applicationContext.xml在web-info下则不用配置-->
      <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
      <!--如果applicationContext.xml不在web-info下则要配置  -->
      <context-param>
      <!-- contextConfigLocation名不能改 -->
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:config/applicationContext.xml</param-value>
      </context-param>
      <display-name></display-name> 
      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
    </web-app>
    
    1. 配置struts文件
    Paste_Image.png

    源码:

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" 
    "http://struts.apache.org/dtds/struts-2.1.dtd">
    <struts>
    <package name="struts" extends="struts-default">
    <!-- 前面是action类名(com.hw.controller.UserAction) ,后面是方法名
    ,如果和spring整合class里也可以用控制层注解 -->
    <action name="user_*" class="userController" method="{1}">
    <result name="add">/WEB-INF/user/add.jsp</result>
    <result name="update">/WEB-INF/user/update.jsp</result>
    <!-- struts中默认为转发即 type="dispatcher",redirect为重定向-->
    <result name="success" type="redirect">user_list</result>
    <result name="list">/WEB-INF/user/list.jsp</result>
    </action>
    </package>
    </struts>
    

    ssh(spring+struts+hibernate) 整合

    相关文章

      网友评论

          本文标题:Spring 框架第二天 ssd整合 ssh分开整合

          本文链接:https://www.haomeiwen.com/subject/kmutlxtx.html