圆形视图路径 [英] Circular view path

查看:494
本文介绍了圆形视图路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using Spring MVC 3 and all I am trying to do is submitting a form with post request and redirecting the post request handler on the controller to some page. But I am getting the following error when I try to do that:

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

查看弹簧应用程序上下文中的解析器:

View resolver in spring application context:

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

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

</bean>

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

I am not quite able to understand what is going on here. I see "redirecting.." being logged and then I get this error. Could someone help me with this issue?

谢谢。

推荐答案

以下解决了问题:

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

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

As you could see, I just changed the redirect from "thanks" to "captured" and modified the "value" for the redirect request handler from "thanks" to "captured" as well and it worked. Thanks.

这篇关于圆形视图路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆