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

一、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) 整合

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容