5

我正在使用 Spring MVC 3,我要做的就是提交一个带有 post 请求的表单并将控制器上的 post 请求处理程序重定向到某个页面。但是当我尝试这样做时出现以下错误:

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>

我不太明白这里发生了什么。我看到“重定向..”被记录,然后我得到这个错误。有人可以帮我解决这个问题吗?

谢谢。

4

1 回答 1

1

以下解决了问题:

@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”,并且它起作用了。谢谢。

于 2012-05-17T20:00:22.617 回答