Redirecting and forwarding to views

In this section, you will learn about redirecting and forwarding views through prefixes.

Ads

Tutorials   
Spring 3.2 MVC insert and retrieve blob from the database The hidden tag The errors tag net.roseindia.dao net.roseindia.service net.roseindia.model net.roseindia.controller Spring 3.2 MVC Hibernate Example Spring 3.2 MVC, Upload File in a specific folder Spring 3.2 MVC Form Handling The textarea tag The options tag The option tag The select tag The radiobuttons tag The radiobutton tag The checkboxes tag mvc:default-servlet-handler Static Resources Configuration View Controllers Configuration View resolvers Spring 3.2 MVC Hello World Example Content Negotiation Configuration Interceptors Configuration using Java or XML Customizing the MVC Java config or XML Namespace MVC Java Config or the MVC XML Namespace Servlet container initialization through code Support for ETag The checkbox tag Autogenerated logical view name through RequestToViewNameTranslator Modification in conventional ModelAndView ControllerClassNameHandlerMapping class for handling convention mapping The password tag The input tag The form tag Form Tag library configuration Customizing the Default Error Page @ExceptionHandler & @ResponseStatus annotation Multipart support for file upload in Spring MVC Themes and Theme resolvers in Spring MVC Locales in Spring MVC ContentNegotiatingViewResolver Redirecting and forwarding to views Chaining of Multiple view resolvers View Resolving through ViewResolver interface Requests Intercepting through a HandlerInterceptor Defining handler methods using @RequestMapping annotation Spring 3.2 Asynchronous Request Processing @RequestMapping annotation for mapping requests @Controller annotation for defining new controller
Ads

Redirecting and forwarding to views

In this section, you will learn about redirecting and forwarding views through prefixes.

Sometimes it became necessary, before the view is resolved, to issue redirect back to the client. For example, when one controller is invoked through form POST but response is really for another controller. In this case, we need normal internal forward which means other controller will also see the posted data which can create confusion. Other reason to execute the redirect before displaying result is to avoid multiple form submission.

The redirect: prefix

If the returned view name has prefix redirect:, the UrlBasedViewResolver and all its subclass get the indication that a redirect need to perform. The rest of the returned view name will be considered as redirect URL.

@RequestMapping("login",method = RequestMethod.POST)
public String showForm(Map model) {
..............................
return "redirect:login";
}



The forward: prefix

If the returned view name has prefix forward: , the UrlBasedViewResolver and all its subclasses get the indication that a forward is needed. The rest of the returned view name will be considered as forward URL. But forward is useful where primarily you are using another view technology  but want to force a forward of a resource which is handled by the Servlet/JSP engine.

@RequestMapping("loginform",method = RequestMethod.POST)
public String showForm(Map model) {
..............................
return "forward:login";
}

Advertisements

Ads
Share on Google+Share on Google+

Redirecting and forwarding to views

Posted on: January 10, 2013 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: Redirecting and forwarding to views  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads