Java Reference
In-Depth Information
Joe Asks. . .
Why Can't I Redirect to a JSP?
A forward to a JSP is part of the response to the initial request,
which was a request to an action bean. A redirect tells the
browser to send a new request. Redirecting to a JSP is like link-
ing directly to a JSP and breaks the pattern that we discussed
in Section 2.3 , The Preaction Pattern, on page 38 .
The Flash Scope
Redirecting introduces a new problem. If you provide information to
the view using attributes in the request scope, those attributes are
kept only for that request. But because the response is a redirect,
the browser issues a second request, for which those attributes are
no longer available.
To solve this problem, Stripes provides what is called the flash scope.
The flash scope stores attributes available for the current request and
the following request. This mechanism provides a bridge for attributes
when using a redirect.
Stripes uses the flash scope where appropriate. For example, the mes-
sages that you add to ActionBeanContext are stored in the flash scope.
When you return a RedirectResolution from an event handler, you can
display the messages in the view with the <s:messages/> tag because
Stripes automatically makes them available for you in the flash scope.
The Story So Far
Using action beans and JSPs as building blocks, you can easily add fea-
tures to a web application with parameterized links, forms, messages,
reusable layouts, and even third-party JSP libraries.
We now have a good start to the webmail application, with a working
contact list. In the next chapter, we'll improve it by adding some user
input validation.
 
 
Search WWH ::




Custom Search