2012-05-12 105 views
4

我正在使用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.) 

以下是我使用的代码:

请求处理程序:在Spring应用程序上下文

@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"; 
} 

视图解析:

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

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

</bean> 

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

谢谢。

+0

我将重定向从“谢谢”更改为“已捕获”,并将重定向请求处理程序的“值”从“谢谢”更改为“已捕获”,并且工作正常。谢谢。 – skip

+0

@ dragon66:就像你建议的那样,我刚刚添加了一个答案,并接受了它。谢谢。 – skip

回答

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"; 
} 

正如你可以看到,我刚刚从“谢谢”来“俘获”改变了重定向和“感谢”来修改的“价值”为重定向请求处理程序“俘获”以及它的工作。谢谢。