《Spring Web Flow 实践》

本文通过一个购物车实例介绍了Spring Web Flow的使用,包括创建Spring MVC项目、配置web.xml、mvc-dispatcher.xml、webflow-config.xml文件,以及流程文件shopping.xml的编写。在实践中遇到了NoClassDefFoundError和HTTP Status 500的问题,并提供了解决方案。文章末尾总结了实践过程中的收获,并提供了完整项目的GitHub链接。
摘要由CSDN通过智能技术生成

《Spring Web Flow 实践》

在《Spring In Action》这本书上的第八章介绍了Spring Web Flow的相关知识。

在《Spring In Action》这本书上是这样介绍的:Spring Web Flow是一个Web框架,它适用于元素按规定流程运行的程序。比较典型的例子就是电子商务站点的结账流程,从购物车开始,应用程序会引导用户依次经过派送详情、账单信息以及最终的订单确认流程。

关于Spring Web Flow,官网上的介绍是这样的:

Spring Web Flow builds on Spring MVC and allows implementing the “flows” of a web application. A flow encapsulates a sequence of steps that guide a user through the execution of some business task. It spans multiple HTTP requests, has state, deals with transactional data, is reusable, and may be dynamic and long-running in nature..

简单的翻译下:Spring Web Flow是建立在Spring MVC上面的,并允许实现web应用程序的“流”。这个流封装了一系列用于指导用户执行业务任务的步骤。它跨越多个HTTP请求,具有状态,可以处理事务数据,而且是可重用的,并且可能是动态的和长期运行的。

和参考资料所列出来的博客一样,本篇博文将按照购物车实例作为例子来学习并实践了下,记录如下。

购物车流程如下所示。

Spring Web Flow购物车实例

具体步骤如下:

1、使用IDEA创建一个新的Spring MVC项目,并添加相关的依赖,pom.xml文件中的内容如下:

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.wrh</groupId>
      <artifactId>springwebflow</artifactId>
      <packaging>war</packaging>
      <version>1.0-SNAPSHOT</version>
      <name>springwebflow Maven Webapp</name>
      <url>http://maven.apache.org</url>
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>org.springframework.webflow</groupId>
          <artifactId>spring-webflow</artifactId>
          <version>2.4.5.RELEASE</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-webmvc</artifactId>
          <version>4.3.8.RELEASE</version>
        </dependency>
          <!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
          <dependency>
              <groupId>org.springframework</groupId>
              <artifactId>spring-web</artifactId>
              <version>4.3.8.RELEASE</version>
          </dependency>
          <!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
          <dependency>
              <groupId>javax.servlet</groupId>
              <artifactId>jstl</artifactId>
              <version>1.2</version>
          </dependency>


      </dependencies>
      <build>
        <finalName>springwebflow</finalName>
      </build>
    </project>

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">

      <display-name>winner-test Web Application</display-name>
      <servlet>
        <servlet-name>mvc-dispatch
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值