Search code examples
springmodel-view-controllerspring-mvcspring-webflow

getting stack overflow during return page from spring mvc controller


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"/>

Solution

  • Two things

    1. For URL mapping, better not to use *.jsp. Use something like jsps/welcome or jsps/welcome.htm
    2. 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.