Results 1 to 3 of 3

Thread: Multiple calls to controller while using SimpleUrlHandlerMapping

  1. #1
    Join Date
    Oct 2010
    Posts
    10

    Default Multiple calls to controller while using SimpleUrlHandlerMapping

    Hello
    It was my first MVC application in which I am tring to invoke my controller. My request is mapped correctly with the controller though handleRequest gets called multile times and finally I get the exception "java.lang.OutOfMemoryError: Java heap space" .
    Following are my details of configuration file (jca-mvc.xml) . (I have declared both configuration file and application specific *-servlet.xml separately)

    <bean class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
    <property name="mappings">
    <props>
    <prop key="/comp/**">componentController</prop>

    </props>
    </property>
    </bean>

    And my application specific file *-servlet.xml is as follows

    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">


    <import resource="jca-mvc.xml" />

    </beans>

    I have decleared handleRequest as follows
    @RequestMapping(method = { RequestMethod.GET, RequestMethod.POST })
    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {

    and my controller is having @controller annotation.

    the URL which I am hitting is
    http://localhost:8080/Mvc/app1/comp/welcome.jsp

  2. #2
    Join Date
    Dec 2010
    Posts
    175

    Question

    can you post your complete web.xml and two spring config files?

  3. #3
    Join Date
    Oct 2010
    Posts
    10

    Default

    Thanks for the reply sir
    I got the issue with the problem mentioned above. Though I am curious to know why spring behave in this way .
    The main culprit was the mapping provided in jca-mvc.xml.

    <bean class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
    <property name="mappings">
    <props>
    <prop key="/comp/**">componentController</prop>
    </props>
    </property>
    </bean>

    When I change the prop key to some fix URL structure it worked fine with me.
    I made following change in <prop key> tag.

    <prop key="/comp/*.do>componentController</prop>

    And it invoked the controller only once when I hit the URL

    http://localhost:8080/Mvc/app1/comp/welcome.do


    Though I am curios to know what is there in the earlier mapping which was causing controller invocation multiple time ? Is it the case that controller was getting invoked for all the permutations and combinations of the URL ?

    Following is the code for jca-mvc.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schem...-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">



    <bean class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
    <property name="mappings">
    <props>
    <prop key="/comp/**">componentController</prop>

    </props>
    </property>
    </bean>





    </beans>



    and here is the code for *-servlet.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">



    <import resource="jca-mvc.xml" />

    </beans>


    Thanks
    Samir

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •