类 RedirectView

  • 所有已实现的接口:
    Aware, BeanNameAware, InitializingBean, ApplicationContextAware, ServletContextAware, SmartView, View

    public class RedirectView
    extends AbstractUrlBasedView
    implements SmartView
    View that redirects to an absolute, context relative, or current request relative URL. The URL may be a URI template in which case the URI template variables will be replaced with values available in the model. By default all primitive model attributes (or collections thereof) are exposed as HTTP query parameters (assuming they've not been used as URI template variables), but this behavior can be changed by overriding the isEligibleProperty(String, Object) method.

    A URL for this view is supposed to be an HTTP redirect URL, i.e. suitable for HttpServletResponse's sendRedirect method, which is what actually does the redirect if the HTTP 1.0 flag is on, or via sending back an HTTP 303 code - if the HTTP 1.0 compatibility flag is off.

    Note that while the default value for the "contextRelative" flag is off, you will probably want to almost always set it to true. With the flag off, URLs starting with "/" are considered relative to the web server root, while with the flag on, they are considered relative to the web application root. Since most web applications will never know or care what their context path actually is, they are much better off setting this flag to true, and submitting paths which are to be considered relative to the web application root.

    NOTE when using this redirect view in a Portlet environment: Make sure that your controller respects the Portlet sendRedirect constraints.

    作者:
    Rod Johnson, Juergen Hoeller, Colin Sampaleanu, Sam Brannen, Arjen Poutsma, Rossen Stoyanchev
    另请参阅:
    setContextRelative(boolean), setHttp10Compatible(boolean), setExposeModelAttributes(boolean), HttpServletResponse.sendRedirect(java.lang.String)