从spring mvc控制器返回页面期间获取堆栈溢出流(getting stack overflow during return page from spring mvc controller)

编程入门 行业动态 更新时间:2024-10-28 13:27:25
从spring mvc控制器返回页面期间获取堆栈溢出流(getting stack overflow during return page from spring mvc controller)

我有spring mvc控制器,包含方法之类的

@requestmapping("jsps/welcome.jsp") public String handleRequest(){ system.out.println("inside the handler"); return "welcome";}

当我尝试运行welcome.jsp页面时,我正在获得堆栈溢出,似乎页面将转到控制器,然后控制器返回页面然后它将再次出现,依此类推。

我的弹簧配置是

<bean id="viewResolver" class="------" <property name="prefix"> <value> /jsps/ </value> </property> <property name="suffix"> <value> .jsp </value> </property>

和urlmapping

<map> <entry key="jsps/welcome.jsp"> <ref bean="mycontroller"/>

对不起,代码不完整,我无法复制粘贴,任何建议?

I have spring mvc controller, contain method like

@requestmapping("jsps/welcome.jsp") public String handleRequest(){ system.out.println("inside the handler"); return "welcome";}

when I am trying to run the welcome.jsp page, I am getting stack overflow, it seems like the page is going to the controller then the controller return the page then it will go again and so on.

my configuration for spring is

<bean id="viewResolver" class="------" <property name="prefix"> <value> /jsps/ </value> </property> <property name="suffix"> <value> .jsp </value> </property>

and the urlmapping

<map> <entry key="jsps/welcome.jsp"> <ref bean="mycontroller"/>

最满意答案

两件事情

对于URL映射,最好不要使用* .jsp。 使用jsps / welcome或jsps / welcome.htm之类的东西 要返回视图,请使用ModelAndVeiw 。

UPDATE

进行这些更改

@requestmapping("jsps/welcome") public String handleRequest(){ system.out.println("inside the handler"); return new ModelAndView("yourpathtojspfile");} // can be "jsps/welcome"

在这里,此页面将返回视图(使用'jsps / welcome',您将获得welcome.jsp)

当您返回一个字符串时,您可以使用该选项

return "redirect:someUrl"; //But this will not return a view, instead search for the mapping someUrl.

Two things

For URL mapping, better not to use *.jsp. Use something like jsps/welcome or jsps/welcome.htm To return a view use ModelAndVeiw.

UPDATE

Make these changes

@requestmapping("jsps/welcome") public String handleRequest(){ system.out.println("inside the handler"); return new ModelAndView("yourpathtojspfile");} // can be "jsps/welcome"

Here, this page will return the view (with 'jsps/welcome' you will get welcome.jsp)

When you return a string, the option you have is to use

return "redirect:someUrl"; //But this will not return a view, instead search for the mapping someUrl.

更多推荐

本文发布于:2023-08-02 13:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1375962.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:堆栈   控制器   页面   mvc   spring

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!