I have wrote following controller:
@RequestMapping(value=\"/logOut\", method = RequestMethod.GET )
public String logOut(Model model, RedirectAttributes r
When the return value contains redirect:
prefix, the viewResolver
recognizes this as a special indication that a redirect is needed. The rest of the view name will be treated as the redirect URL. And the client will send a new request to this redirect URL
. So you need to have a handler method mapped to this URL to process the redirect request.
You can write a handler method like this to handle the redirect request:
@RequestMapping(value="/home", method = RequestMethod.GET )
public String showHomePage() {
return "home";
}
And you can re-write the logOut
handler method as this:
@RequestMapping(value="/logOut", method = RequestMethod.POST )
public String logOut(Model model, RedirectAttributes redirectAttributes) {
redirectAttributes.addFlashAttribute("message", "success logout");
System.out.println("/logOut");
return "redirect:/home";
}
EDIT:
You can avoid showHomePage
method with this entry in your application config file:
<beans xmlns:mvc="http://www.springframework.org/schema/mvc"
.....
xsi:schemaLocation="...
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
....>
<mvc:view-controller path="/home" view-name="home" />
....
</beans>
This will forward a request for /home
to a view called home
. This approach is suitable if there is no Java controller logic to execute before the view generates the response.