Java Reference
In-Depth Information
request: delete
ContactListActionBean
delete()
Browser
response
forward
JSP
Figure 3.14: Using a forward after a delete request
request: delete
ContactListActionBean
delete()
Browser
redirect
ContactListActionBean
list()
request: (default)
Browser
response
forward
JSP
Figure 3.15: Using a redirect after a delete request
The “redirect after side effect” pattern comes to the rescue. Also known
as “redirect after post” or “post/redirect/get,” it involves sending a
redirect—a response that instructs the browser to issue a new request
that does not modify any data. According to Figure 3.15 , we're redirect-
ing to the default event handler of the action bean, which just displays
the contact list. Clicking Reload is harmless: the request that is re-sent
is the request to view the contact list, which has no side effect.
Using a redirect prevents unsafe behavior and eliminates those annoy-
ing “The page you are trying to view contains POSTDATA. . . ” pop-up
warnings. Get in the habit of using redirects to default event handlers
of action beans at the end of event handlers that modify the state of
the server. Of course, those default event handlers should do read-only
operations.
 
 
 
Search WWH ::




Custom Search