Getting started with Spring Web Flow 2.0

Source: Internet
Author: User

As I said earlier, Spring Web flow provides the abstraction to describe business processes, but that's not enough for a Web development technology. Also, can Spring Web flow replace other Web MVC technologies? Or should you use Spring Web flow preferentially in any case? To answer these questions, take a look at the technical issues that Spring Web flow has focused on.

Three scopes for WEB applications

The Java Servlet specification sets three scopes (scope) for the various objects used by WEB applications, namely, the request scope, session scope, and application scope.

The objects in the request scope are bound to the customer's request and the object is destroyed at the end of each request, and the new request is recreated when it comes up. The request scope is suitable for temporary data with large amounts of data.

Objects in the session scope are bound together with sessions, which are destroyed at the end of each session and re-created in new sessions. HTTP protocol itself is stateless, the server and the client to implement session management, can only rely on a number of auxiliary means, such as the packet in the protocol to add some hidden tokens, and so on. The session scope is suitable for storing data that needs to be retained for this conversation.

Application-scoped objects are bound to the application itself, and, from the servlet API's point of view, are objects stored in ServletContext that are created as the servlet is started and are destroyed when the servlet closes. The application range is suitable for storing data that is globally relevant to the application.

One of the biggest headaches in real-world development is the session scope, where the Java Servlet specification indicates that the session can be configured as follows in Web.xml for 100 minutes:

Listing 2 The session configuration in Web.xml

<session-config>
<session-timeout>100</session-timeout>
</session-config>

However, the reality of the scope of the session is more like "chicken", put a large number of data into the session will lead to serious efficiency problems, in the distributed environment to deal with the scope of the session is inadvertently will be wrong, but discard the session will bring a lot of inconvenience to the development. The request scope, although it can store a large amount of data, but the effective range is limited. Many of the use cases placed in front of the developer require an effective range that is longer than the request scope, but shorter than the session scope.

Solution for Spring Web flow

For this flaw in the Java Servlet specification, the following two ranges are available in Spring Web Flow 2.0:

Flow range. Objects within this scope are created at the start of the flow, destroyed at the end of the flow, and accessed through the "flowscope" variable name in the flow definition file.

Conversation Range. Objects within this scope are basically similar to flow-scoped objects, except that the flow within the conversation scope can be accessed in Subflow if other subflow are invoked.

Note: Subflow definition: A flow called by another flow can be called a subflow.

Because flow is defined by the developers themselves and can be freely changed according to the needs of the business, the use of the flow scope and conversation scope breaks through the limitations of Session scope and request scope in the Java Servlet specification and is truly free to customize.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.