1.构建webflow2.3.3环境(2.0以上应该都可以)

导入webflow的jar包+springmvc的一些必须包,目录结构如下

2.配置webflow(spring-wf.xml)

<?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:webflow="http://www.springframework.org/schema/webflow-config"xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd"><!-- 流程注册器 隐含一句 flow-registry="flowRegistry" 默认表示引用bean id为 'flowRegistry'的流程注册表--><webflow:flow-executor id="flowExecutor" /><!-- 流程注册表 --><webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices"><webflow:flow-location path="/WEB-INF/flows/hello.xml" id="hello" /></webflow:flow-registry><!-- WebFlow 视图解析器 -->   <bean id="flowViewResolver"class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="viewClass"value="org.springframework.web.servlet.view.JstlView"></property><property name="prefix" value="/WEB-INF/flowView/"></property><property name="suffix" value=".jsp"></property> </bean><!-- WebFlow 视图工厂构建服务 --><webflow:flow-builder-services id="flowBuilderServices" view-factory-creator="mvcViewFactoryCreator" /><!-- WebFlow 视图工厂创建器,表示使用视图解析器将流程配置(xml)中的逻辑视图交给视图解析器解析 → jsp --><bean id="mvcViewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator"><property name="viewResolvers" ref="flowViewResolver" /></bean><!-- 配置WebFlow 处理器映射器--><bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"><property name="mappings"><props><!-- 这个逻辑视图名的 前缀 必须与流程注册表中的webflow:flow-location 的 id一致,而 后缀 必须是当前DispatcherServlet匹配的地址,也就是必须以.flow结束,否则不被前端控制器处理(视图名必须匹配*.flow)--><!-- 这里代表将请求路径为hello.flow的url交给flowController处理 --><prop key="hello.flow">flowController</prop></props></property></bean><!--WebFlow 处理器,根据逻辑视图名到流程执行器中找到对应的注册表,进而找到流程配置文件,转到不同的物理视图--><!--主要工作就是负责将url转化成逻辑视图交给视图解析器解析 → jsp--><bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController"><property name="flowExecutor" ref="flowExecutor" /></bean>
</beans>

3.配置WebFlow前端控制器(web.xml)

<servlet><servlet-name>FlowServlet</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value> classpath:spring-wf.xml </param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>FlowServlet</servlet-name><url-pattern>*.flow</url-pattern></servlet-mapping>

拦截所有.flow结尾的请求交给springmvc前端控制器处理

至此,webflow需要的所有组件都已经配置完成,现在还有2步,配置流程文件+跳转页面

4.流程配置文件(hello.xml[/WEB-INF/flow])

<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/webflowhttp://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd"><view-state id="cart" view="cart"><transition on="submit" to="order"></transition></view-state><view-state id="order" view="order"><transition on="confirm" to="finish"></transition></view-state><view-state id="finish" view="finish"><transition on="toindex" to="index"></transition></view-state><end-state id="index" view="externalRedirect:index.jsp"></end-state>
</flow>

流程配置文件首先执行第一个状态标签。

5.跳转页面

index.jsp(根目录)

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>index</title>
</head>
<body><h2 align="center">Hello,WebFlow</h2><br />Item1:<a href="hello.flow">加入购物车</a><br />Item2:<a href="hello.flow">加入购物车</a><br />Item2:<a href="hello.flow">加入购物车</a>
</body>
</html>

cart.jsp(/WEB-INF/flowView/)

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>购物车</title>
</head>
<body><h2 align="center">购物车</h2><br/>衣服:<a href="${flowExecutionUrl}&_eventId=submit">买买买!!!</a><br/>裤子:<a href="${flowExecutionUrl}&_eventId=submit">买买买!!!</a><br/>鞋子:<a href="${flowExecutionUrl}&_eventId=submit">买买买!!!</a>
</body>
</html>

order.jsp(/WEB-INF/flowView/)

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>订单</title>
</head>
<body><h2 align="center">订单</h2><br/><a href="${flowExecutionUrl}&_eventId=confirm">确认支付</a>
</body>
</html>

finish.jsp(/WEB-INF/flowView/)

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>view order</title>
</head>
<body><h2 align="center">确认支付</h2><br/><a href="${flowExecutionUrl}&_eventId=toindex">恭喜你,支付成功..</a>
</body>
</html>

${flowExecutionUrl}由webflow框架赋值,其中包含了flow各个状态的值(动态生成,每个状态不一样),以及对应的model数据

_eventId的值与本状态transition标签的on属性值对应,通过这个值跳转到不同的状态或者视图,实现转移

Spring Web Flow入门(带详细注释)相关推荐

  1. Spring Web Flow 入门demo(二)与业务结合 附源码

    转载地址 http://blog.csdn.net/hejingyuan6/article/details/46516287 第一部分demo仅仅介绍了简单的页面跳转,接下来我们要实现与业务逻辑相关的 ...

  2. Spring Web Flow 入门demo(二)与业务结合 附源代码

    第一部分demo仅仅介绍了简单的页面跳转,接下来我们要实现与业务逻辑相关的功能. 业务的逻辑涉及到数据的获取.传递.保存.相关的业务功能函数的调用等内容,这些功能的实现都可用Java 代码来完毕,但定 ...

  3. Spring Web Flow 入门demo(三)嵌套流程与业务结合 附源码

    转载地址 ; http://blog.csdn.net/hejingyuan6/article/details/46723021 上篇博客我们说spring web Flow与业务结合的方式主要有三种 ...

  4. Spring Web Flow 入门demo(一)简单页面跳转 附源码

    转载地址 http://blog.csdn.net/hejingyuan6/article/details/46508821 spring Web Flow (SWF)是Spring Framewor ...

  5. Spring Web Flow 2.0 入门

    Spring Web Flow 2.0 入门 本教程分析了 Spring Web Flow 2.0 的技术要点,并且通过创建一个示例应用程序,展示了 Spring Web Flow 2.0 的基本知识 ...

  6. Spring Web Flow 2.0 入门详解

    目录: 参考文献 购物车用例 什么情况下可以使用 Spring Web Flow? 配置 Spring Web MVC 配置 Spring Web Flow 2.0 的基础 在购物车示例应用中配置 S ...

  7. Spring Web Flow实例教程

    目录: 参考文献 购物车用例 什么情况下可以使用 Spring Web Flow? 配置 Spring Web MVC 配置 Spring Web Flow 2.0 的基础 在购物车示例应用中配置 S ...

  8. Spring Web Flow —— 配置 - 001

    本文基于Spring Web Flow 2.4.5,其它版本配置方式可能略有不同,请参考相应版本的官方文档 Maven依赖 maven库查询推荐地址:http://mvnrepository.com/ ...

  9. 用Spring Web Flow和Terracotta搭建Web应用

    什么是Spring Web Flow? Spring Web Flow是Spring Framework中的web应用组件,它提供了一种编写有状态和基于会话的web应用的简便手段.Spring Web ...

最新文章

  1. Java内存模型深度解析:锁--转
  2. 自己写了个nginx启动脚本,shell
  3. 【Linux】一步一步学Linux——gdb命令(258)
  4. MySQL子查询操作实例详解
  5. wdcp mysql密码_wdcp默认的mysql密码是多少?
  6. .Net Framework 4.5 zip压缩原生支持
  7. mysql中timestamp,datetime,int类型的区别与优劣
  8. 裁员下老公老婆的对话
  9. jmeter自动生成测试报告
  10. js html方法的区别吗,jquery append()方法与html()方法的区别及使用介绍
  11. 程序猿不能不知道的网站
  12. Centos操作系统:文件的上传、下载、压缩、解压缩
  13. 计算机如何永久删除文件无法找回,怎么找回永久删除文件 找回永久删除文件方法【详细步骤】...
  14. VTK:输出将样条拟合到刀具Cutter用法实战
  15. Egret 学习笔记
  16. 安卓开发 java.lang.IllegalStateException isPlaying() 解决方案
  17. win7 win8 系统ntoskrnl.exe丢失引起蓝屏的问题解决以及ntoskrnl.exe下载位置
  18. 计算机组成原理总复习——题目练习
  19. 解决远程连接服务器的最大连接数
  20. Mybatis的批量插入的正确姿势

热门文章

  1. 生活嘛,没有那么多上火的事情(r9笔记第90天)
  2. ubuntu 9.10 ppstream 网络电视安装
  3. ofstream文件输出流把二进制数据写入文件
  4. QueueUserWorkItem(WaitCallback, Object)
  5. 软件测试简单经验心得分享
  6. php onload,onload 和 onreadystatechange
  7. 嵌入式数据库在Java中的应用
  8. 【每日一题Day95】LC1815得到新鲜甜甜圈的最多组数 | 状态压缩dp 记忆化搜索
  9. dlib php,dlib库19.0下载
  10. Android操作响应时间测试方法