圆形检视路径
问题内容:
我正在使用Spring MVC 3,我要做的就是提交带有发布请求的表单,并将控制器上的发布请求处理程序重定向到某个页面。但是,当我尝试这样做时出现以下错误:
javax.servlet.ServletException: Circular view path [thanks.htm]: would dispatch back to the current handler URL [/wickedlysmart/thanks.htm] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)
以下是我正在使用的代码:
请求处理程序:
@RequestMapping(method=RequestMethod.GET, value="thanks")
public ModelAndView thanks() {
logger.debug("redirecting..");
return new ModelAndView("thanks");
}
@RequestMapping(method = RequestMethod.POST, value="talk")
public String processContactForm(HttpServletRequest req) {
//...
return "redirect:thanks";
}
在Spring应用程序上下文中查看解析器:
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="" />
<property name="suffix" value=".htm" />
</bean>
我不太了解这里发生了什么。我看到正在记录“重定向。”,然后出现此错误。有人可以帮我解决这个问题吗?
谢谢。
问题答案:
以下解决了问题:
@RequestMapping(method=RequestMethod.GET, value="captured")
public ModelAndView thanks() {
logger.debug("redirecting..");
return new ModelAndView("thanks");
}
@RequestMapping(method = RequestMethod.POST, value="talk")
public String processContactForm(HttpServletRequest req) {
//...
return "redirect:captured";
}
如您所见,我将重定向从“ thanks”更改为“ captured”,并将重定向请求处理程序的“ value”也从“ thanks”更改为“
captured”,并且可以正常工作。谢谢。