net.sourceforge.stripes.action
Class RedirectResolution

java.lang.Object
  extended by net.sourceforge.stripes.action.OnwardResolution<RedirectResolution>
      extended by net.sourceforge.stripes.action.RedirectResolution
All Implemented Interfaces:
Resolution

public class RedirectResolution
extends OnwardResolution<RedirectResolution>
implements Resolution

Resolution that uses the Servlet API to redirect the user to another path by issuing a client side redirect. Unlike the ForwardResolution the RedirectResolution can send the user to any URL anywhere on the web - though it is more commonly used to send the user to a location within the same application.

By default the RedirectResolution will prepend the context path of the web application to any URL before redirecting the request. To prevent the context path from being prepended use the constructor: RedirectResolution(String,boolean).

It is also possible to append parameters to the URL to which the user will be redirected. This can be done by manually adding parameters with the addParameter() and addParameters() methods, and by invoking includeRequestParameters() which will cause all of the current request parameters to be included into the URL.

Author:
Tim Fennell
See Also:
ForwardResolution

Constructor Summary
RedirectResolution(Class<? extends ActionBean> beanType)
          Constructs a RedirectResolution that will redirect to the URL appropriate for the ActionBean supplied.
RedirectResolution(Class<? extends ActionBean> beanType, String event)
          Constructs a RedirectResolution that will redirect to the URL appropriate for the ActionBean supplied.
RedirectResolution(String url)
          Simple constructor that takes the URL to which to forward the user.
RedirectResolution(String url, boolean prependContext)
          Constructor that allows explicit control over whether or not the context path is prepended to the URL before redirecting.
 
Method Summary
 void execute(HttpServletRequest request, HttpServletResponse response)
          Attempts to redirect the user to the specified URL.
 RedirectResolution flash(ActionBean bean)
          Causes the ActionBean supplied to be added to the Flash scope and made available during the next request cycle.
 String getAnchor()
          This method is overridden to make it public.
 RedirectResolution includeRequestParameters(boolean inc)
          If set to true, will cause absolutely all request parameters present in the current request to be appended to the redirect URL that will be sent to the browser.
 RedirectResolution setAnchor(String anchor)
          This method is overridden to make it public.
 
Methods inherited from class net.sourceforge.stripes.action.OnwardResolution
addParameter, addParameters, getParameters, getPath, getUrl, getUrl, setPath, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RedirectResolution

public RedirectResolution(String url)
Simple constructor that takes the URL to which to forward the user. Defaults to prepending the context path to the url supplied before redirecting.

Parameters:
url - the URL to which the user's browser should be re-directed.

RedirectResolution

public RedirectResolution(String url,
                          boolean prependContext)
Constructor that allows explicit control over whether or not the context path is prepended to the URL before redirecting.

Parameters:
url - the URL to which the user's browser should be re-directed.
prependContext - true if the context should be prepended, false otherwise

RedirectResolution

public RedirectResolution(Class<? extends ActionBean> beanType)
Constructs a RedirectResolution that will redirect to the URL appropriate for the ActionBean supplied. This constructor should be preferred when redirecting to an ActionBean as it will ensure the correct URL is always used.

Parameters:
beanType - the Class object representing the ActionBean to redirect to

RedirectResolution

public RedirectResolution(Class<? extends ActionBean> beanType,
                          String event)
Constructs a RedirectResolution that will redirect to the URL appropriate for the ActionBean supplied. This constructor should be preferred when redirecting to an ActionBean as it will ensure the correct URL is always used.

Parameters:
beanType - the Class object representing the ActionBean to redirect to
event - the event that should be triggered on the redirect
Method Detail

getAnchor

public String getAnchor()
This method is overridden to make it public.

Overrides:
getAnchor in class OnwardResolution<RedirectResolution>

setAnchor

public RedirectResolution setAnchor(String anchor)
This method is overridden to make it public.

Overrides:
setAnchor in class OnwardResolution<RedirectResolution>

includeRequestParameters

public RedirectResolution includeRequestParameters(boolean inc)
If set to true, will cause absolutely all request parameters present in the current request to be appended to the redirect URL that will be sent to the browser. Since some browsers and servers cannot handle extremely long URLs, care should be taken when using this method with large form posts.

Parameters:
inc - whether or not current request parameters should be included in the redirect
Returns:
RedirectResolution, this resolution so that methods can be chained

flash

public RedirectResolution flash(ActionBean bean)
Causes the ActionBean supplied to be added to the Flash scope and made available during the next request cycle.

Parameters:
bean - the ActionBean to be added to flash scope
Since:
Stripes 1.2

execute

public void execute(HttpServletRequest request,
                    HttpServletResponse response)
             throws ServletException,
                    IOException
Attempts to redirect the user to the specified URL.

Specified by:
execute in interface Resolution
Parameters:
request - the current HttpServletRequest
response - the current HttpServletResponse
Throws:
ServletException - thrown when the Servlet container encounters an error
IOException - thrown when the Servlet container encounters an error


? Copyright 2005-2006, Stripes Development Team.