Announcement Announcement Module
Collapse
No announcement yet.
How does one chain controllers? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How does one chain controllers?

    I wonder how does onego about chaining controllers? It should probably be easy I am just not seeing it clearly.

    So, sometimes my controller returns a view and a model, but other times it actually need to go directly to another controller. However, if I overwrite handleRequestInternal of AbstractController, I will have to return the view name that I want to go to next which invariably gets fed to the view resolver and and dispatcher renders the view. So what do I do to actually chain to a controller instead?

    Thanks,
    Alex.

  • #2
    I think (although I've yet to do it) that you can do something like:
    Code:
    return new ModelAndView(new RedirectView("foo.do"));
    The controller that you've mapped in your *-servlet.xml should then kick in.
    Code:
    <bean id="urlMapping" 
            class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
      <property name="mappings">
         <props>
            <prop key="/foo.do">myControllerBeanId</prop>
         </props>
      </property>
    </bean>
    Hope this is helpful.

    Comment


    • #3
      This incurs roundtrip to the client browser as this does response.sendRedirect (); --> not very nice :-(

      Another drawbak, I think (I have not tested this, so I might be wrong here), this will expose my attributes on the command line; so my POST request will turn into GET.

      Any other ideas?

      Comment


      • #4
        you can possibly do something with org.springframework.web.servlet.view.InternalResou rceView, which performs a forward.

        There are various posts in this forum on using this, so you might want to read them first ?.

        Greg.

        Comment

        Working...
        X