圆形视图路径

ski*_*kip 5 servlets spring-mvc http-post

我正在使用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.)
Run Code Online (Sandbox Code Playgroud)

以下是我使用的代码:

请求处理程序

@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";
}
Run Code Online (Sandbox Code Playgroud)

在Spring应用程序上下文中查看解析器:

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

    <property name="prefix" value="" />
    <property name="suffix" value=".htm" />

</bean>
Run Code Online (Sandbox Code Playgroud)

我不太能理解这里发生了什么.我看到"重定向..."正在记录,然后我收到此错误.有人可以帮我解决这个问题吗?

谢谢.

ski*_*kip 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";
}
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我只是将重定向从“感谢”更改为“捕获”,并将重定向请求处理程序的“值”从“感谢”修改为“捕获”,并且它有效。谢谢。