gst*_*low 6 java spring spring-mvc
我写过以下控制器:
@RequestMapping(value="/logOut", method = RequestMethod.GET )
public String logOut(Model model, RedirectAttributes redirectAttributes) {
redirectAttributes.addFlashAttribute("message", "success logout");
System.out.println("/logOut");
return "redirect:home.jsp";
}
Run Code Online (Sandbox Code Playgroud)
如何更改home.jsp我在页面上可以编写${message}和查看的代码"success logout"
当返回值包含redirect:前缀时,将其viewResolver识别为需要重定向的特殊指示.视图名称的其余部分将被视为重定向URL.客户端将向此发送新请求redirect URL.因此,您需要将映射到此URL的处理程序方法处理重定向请求.
您可以编写这样的处理程序方法来处理重定向请求:
@RequestMapping(value="/home", method = RequestMethod.GET )
public String showHomePage() {
return "home";
}
Run Code Online (Sandbox Code Playgroud)
你可以重写这个logOut处理程序方法:
@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";
}
Run Code Online (Sandbox Code Playgroud)
编辑:
您可以showHomePage在应用程序配置文件中避免使用此条目的方法:
<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>
Run Code Online (Sandbox Code Playgroud)
这将转发对/home名为的视图的请求home.如果在视图生成响应之前没有要执行的Java控制器逻辑,则此方法是合适的.
| 归档时间: |
|
| 查看次数: |
28857 次 |
| 最近记录: |