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">
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">
Order Confirmed
index
viewCart.jsp:
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
View Cart
viewOrder.jsp:
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Order
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">
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">
pom.xml
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">