第8章—使用Spring Web Flow—Spring Web Flow的配置

第8章—使用Spring Web Flow—Spring Web Flow的配置

Spring中配置Web Flow

Spring Web Flow 是 Spring 的一个子项目,其最主要的目的是解决跨越多个请求的、用户与服务器之间的、有状态交互问题,比较适合任何比较复杂的、有状态的、需要在多个页面之间跳转的业务过程。

最常见的流程就是购物的流程了:

加入购物车-->查看购物车-->提交订单-->付款-->返回首页:

image

项目结构如图所示:(由于是jsp之间互相的跳转,我们这边没有加入java文件夹)

image

相关代码如下所示:

mvc-dispatcher.xml:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:p="http://www.springframework.org/schema/p"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:mvc="http://www.springframework.org/schema/mvc"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/mvc

http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context.xsd">

webflow-config.xml:

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

webmvc-config.xml:

xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd">

class="org.springframework.web.servlet.view.InternalResourceViewResolver">

value="org.springframework.web.servlet.view.JstlView"/>

class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">

flowController

shopping.xml:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/webflow

http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">

orderConfirmed.jsp:

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Cart Application

Order Confirmed

Return to

index

viewCart.jsp:

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Cart Application

View Cart

Submit

viewOrder.jsp:

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Cart Application

Order

Confirm

web.xml:

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

winner-test Web Application

mvc-dispatcher

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:mvc-dispatcher.xml

1

mvc-dispatcher

*.do

index.jsp

index.jsp:

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

winner-test Web Application

mvc-dispatcher

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:mvc-dispatcher.xml

1

mvc-dispatcher

*.do

index.jsp

pom.xml

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

4.0.0

com.wrh

springwebflow

war

1.0-SNAPSHOT

springwebflow Maven Webapp

http://maven.apache.org

junit

junit

3.8.1

test

org.springframework.webflow

spring-webflow

2.4.5.RELEASE

org.springframework

spring-webmvc

4.3.8.RELEASE

org.springframework

spring-web

4.3.8.RELEASE

javax.servlet

jstl

1.2

springwebflow

相关科技文章

《QQ炫舞》星运传说活动攻略图文详解
365bet官方网站是多少

《QQ炫舞》星运传说活动攻略图文详解

⌚ 08-05 👁️ 9255
腿部减肥法
Bet体育365提款不到账

腿部减肥法

⌚ 07-23 👁️ 8203
苑刚八字分析,苑刚是河北哪里人
365bet官方网站是多少

苑刚八字分析,苑刚是河北哪里人

⌚ 07-08 👁️ 3013
苏州十大老街排行榜:来苏州必去的十条老街 苏州旅行攻略
365体育平台怎么不取缔

苏州十大老街排行榜:来苏州必去的十条老街 苏州旅行攻略

⌚ 07-12 👁️ 2914
beast耳机
Bet体育365提款不到账

beast耳机

⌚ 07-25 👁️ 4844

合作伙伴