这是一个简单的页面重定向示例。当我点击它的按钮重定向页面时,它不起作用。它显示找不到页面。
final.jsp
<body>
<h2>Redirected Page</h2>
</body>
HelloController.java
@Controller
public class HelloController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public String index(Model m) {
return "index";
}
@RequestMapping(value = "/redirect", method = RequestMethod.GET)
public String redirect() {
return "redirect:finalPage";
}
@RequestMapping(value = "/finalPage", method = RequestMethod.GET)
public String finalPage(Model m) {
return "final";
}
的index.jsp
<body>
<h2>Spring Page Redirection</h2>
<p>Click below button to redirect the result to new page</p>
<form:form method="GET" action="/finalPage">
<table>
<tr>
<td>
<input type="submit" value="Redirect Page"/>
</td>
</tr>
</table>
</form:form>
</body>
的web.xml
答案 0 :(得分:1)
错过/重定向:finalpage。它应该是这样的
@RequestMapping(value = "/redirect", method = RequestMethod.GET)
public String redirect() {
return "redirect:/finalPage";
}
但是你从哪里调用/重定向?
答案 1 :(得分:1)
返回的重定向字符串错误,请尝试:"redirect:/finalPage"
答案 2 :(得分:0)
请同时查看here。基本上,你需要在你的项目中有一个UrlBasedViewResolver
子类,并在那里有最终视图,如果它不在root中。