第一步:写好ACtion

package com.inspur.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.inspur.forms.*;

public class LoginAction extends DispatchAction {
 //响应登录
  public ActionForward login(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {
   System.out.println("******通过新的方式响应请求***********");
   /*
   
   EmployeeForm employeeForm=(EmployeeForm)form;
   //构建一个Employee对象
   Employee e=new Employee();
   e.setId(employeeForm.getId());
   e.setName(employeeForm.getName());
   e.setLeader(employeeForm.getLeader());
   e.setMid("111111");
   eif.addEmployee(e);
   request.getSession().setAttribute("adder", e);
   */
   return mapping.findForward("ok");
  }
  
}

第二步:配置structs:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//
DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
 <form-beans>
 <form-bean name="userForm" type="com.inspur.forms.UserForm" />
 </form-beans>
 <action-mappings>
 <action path="/login" parameter="flag" name="userForm" >
 <forward name="ok" path="/WEB-INF/welcome.jsp"/>
 <forward name="err" path="/WEB-INF/login.jsp"/> 
 </action>
 </action-mappings>
 <!-- 配置代理请求处理 DelegatingRequestProcessor ,它的用户是
 
  -->
 <!--这里配置代理,用spring 框架代理sruts-->
 <controller>
   <set-property property="processorClass" value="org.springframework.web.struts.DelegatingRequestProcessor"/>
 </controller>
</struts-config>

第三步:搭建spring框架:

(1)applicationContext.xml一般放在src目录下:

<?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:context="http://www.springframework.org/schema/context"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<!-- 配置action -->
<bean name="/login" scope="prototype" class="com.inspur.actions.LoginAction">
</bean>
</beans>

(2)让web.xml配置好,好让web容器初始化struts以及spring:

<?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" version="3.0">
  <display-name>VoteSystem</display-name>
 
 
  <!-- 开始配置struts -->
  <servlet>
 <servlet-name>struts</servlet-name>
 <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
 <init-param>
  <param-name>config</param-name>
  <param-value>/WEB-INF/struts-config.xml</param-value>
 </init-param>
 <load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
 <servlet-name>struts</servlet-name>
 <url-pattern>*.do</url-pattern>
</servlet-mapping>

<!-- 指定spring的配置文件,默认从web根目录寻找配置文件,我们可以通过spring提供的classpath:前缀指定从类路径下寻找 -->
<context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!-- 对Spring容器进行实例化 -->
<listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>
</web-app>

将Struts放入spring框架中的更多相关文章

  1. 漫谈 GOF 设计模式在 Spring 框架中的实现

    原文地址:梁桂钊的博客 博客地址:http://blog.720ui.com 欢迎关注公众号:「服务端思维」.一群同频者,一起成长,一起精进,打破认知的局限性. 漫谈 GOF 设计模式在 Spring ...

  2. 设计模式在 Spring 框架中的良好应用

    在开始正文之前,请你先思考几个问题: 你项目中有使用哪些 GOF 设计模式 说一说 GOF 23 种设计模式的设计理念 说说 Spring 框架中如何实现设计模式 假设我是面试官问起了你这些面试题,你 ...

  3. 再析在spring框架中解决多数据源的问题

    在前面我写了<如何在spring框架中解决多数据源的问题>,通过设计模式中的Decorator模式在spring框架中解决多数据源的问题,得到了许多网友的关注.在与网友探讨该问题的过程中, ...

  4. Spring框架中 配置c3p0连接池 完成对数据库的访问

    开发准备: 1.导入jar包: ioc基本jar jdbcTemplate基本jar c3p0基本jar 别忘了mysql数据库驱动jar 原始程序代码:不使用配置文件方式(IOC)生成访问数据库对象 ...

  5. Spring框架中ModelAndView、Model、ModelMap区别

    原文地址:http://www.cnblogs.com/google4y/p/3421017.html SPRING框架中ModelAndView.Model.ModelMap区别   注意:如果方法 ...

  6. Spring框架中的定时器 使用和配置

    Spring框架中的定时器 如何使用和配置 转载自:<Spring框架中的定时器 如何使用和配置>https://www.cnblogs.com/longqingyang/p/554543 ...

  7. 细说shiro之五:在spring框架中集成shiro

    官网:https://shiro.apache.org/ 1. 下载在Maven项目中的依赖配置如下: <!-- shiro配置 --> <dependency> <gr ...

  8. 【Spring】8、Spring框架中的单例Beans是线程安全的么

    看到这样一个问题:spring框架中的单例Beans是线程安全的么? Spring框架并没有对单例bean进行任何多线程的封装处理.关于单例bean的线程安全和并发问题需要开发者自行去搞定.但实际上, ...

  9. Spring5源码解析-Spring框架中的单例和原型bean

    Spring5源码解析-Spring框架中的单例和原型bean 最近一直有问我单例和原型bean的一些原理性问题,这里就开一篇来说说的 通过Spring中的依赖注入极大方便了我们的开发.在xml通过& ...

随机推荐

  1. python 取当前日期

    import time time.strftime('%Y-%m-%d',time.localtime(time.time()))

  2. 【Django】ModuleNotFoundError: No module named 'books_ordersschool'

    Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x00000 ...

  3. 库的操作&表的操作

    一 库的操作 掌握库的增删改查 一.系统数据库 执行如下命令,查看系统库 show databases; information_schema: 虚拟库,不占用磁盘空间,存储的是数据库启动后的一些参数 ...

  4. linux自旋锁、互斥锁、信号量

    为了避免并发,防止竞争.内核提供了一组同步方法来提供对共享数据的保护. 我们的重点不是介绍这些方法的详细用法,而是强调为什么使用这些方法和它们之间的差别. Linux 使用的同步机制可以说从2.0到2 ...

  5. MySQL的四种不同查询的分析

    1.前置条件: 本次是基于小数据量,且数据块在一个页中的最理想情况进行分析,可能无具体的实际意义,但是可以借鉴到各种复杂条件下,因为原理是相同的,知小见大,见微知著! 打开语句分析并确认是否已经打开 ...

  6. POJ 2230 Watchcow(有向图欧拉回路)

    Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to walk across the ...

  7. python + selenium 学习笔记 -摘要

    一.浏览器操作相关 from selenium import webdriver driver = webdriver.Chrome() driver.maximize_window() # 窗口最大 ...

  8. FortiGate防火墙内存使用率高问题

    1.现象:zabbix监控到防火墙内存使用率频繁超过80%,而FortiGate防火墙内存超过80%将开启自身保护模式而不能新加策略等. 2.分析:这种情况一般是某些进程再释放内存的时候卡住.可以先查 ...

  9. f5售后查询

    登录: https://secure.f5.com/validate/validate.jsp http://boochem.blog.51cto.com/628505/633907

  10. 细说GIT分布式版本控制器

    一.Git介绍 Git是目前世界上最先进的分布式版本控制器.Svn CVS 版本控制器:就是用来追溯自己书写的代码的记录信息.好处:可以非常方便的记录何时何地何人操作了哪些代码. 什么是分布式版本控制 ...