Results 1 to 5 of 5

Thread: should i pass the ModelAndView content to the next URL request?

  1. #1
    Join Date
    Aug 2008
    Location
    Beijing, China
    Posts
    21

    Wink should i pass the ModelAndView content to the next URL request?

    I have setup a simpleFormController (regController.java) to handle register new users function, as the success view pointing to userHome.do. i am hesitate to write another controller to handle userHome.do because all user information has been put into the ModelAndView by the regController.java.

    if i have to write another controller to deal with userHome.do, how can i pass the ModelAndView from the regController to this new controller?

    if i don't have to write a new controller, how can i get user information to be displayed on the userHome.do ?

    Any thoughts will be appreciated.
    Last edited by victorysoccer; Nov 4th, 2009 at 03:07 AM.

  2. #2
    Join Date
    Oct 2009
    Posts
    7

    Default

    Hi,
    if I got well, I think you lose the request context when redirecting without controller, a workaround is to put the model in the session so that you will be able to access them in userHome.do. Maybe it is better to clear the session thereafter.

    hth,
    mman
    Last edited by mazman; Nov 4th, 2009 at 05:36 AM. Reason: when clause was missed

  3. #3
    Join Date
    Aug 2008
    Location
    Beijing, China
    Posts
    21

    Smile

    my purpose is to redirect using the successview property from the simpleformcontroller itself. on top of that i don't want to just write a jsp destination coz i will still need the controller to provide the viewconfigurations for web pages.

    when you mention writing ModelAndView to the session, how can i do that?

  4. #4
    Join Date
    Oct 2009
    Posts
    7

    Default

    Hi again,
    when you mention writing ModelAndView to the session, how can i do that?
    In onSubmit method - The "model" can be added to the session:

    Code:
    request.getSession.setAttribute("myObject", myObject);
    in JSP you can get it back, e.g. in EL: ${myObject} or:

    Code:
    <% Object obj = request.getSession.getAttribute("myObject");%>
    to clear it:
    Code:
    request.getSession.setAttribute("myObject", null);
    sorry if this won't help :-(

    mman

  5. #5
    Join Date
    Aug 2008
    Location
    Beijing, China
    Posts
    21

    Default

    Thanks mazman,
    Is there another way to pass the information without mannuallg writing them into the httpsession?

    since the flow goes like this:
    http request ---> controller ---> modelandview --->successview ---> http request ---> controller ---> modelandview ---> web pages.
    i just need the result to be passed into another controller. i don't feel comfortable doing that. maybe that's the only way of implementing spring mvc when dealing with this kind of situation?

Tags for this Thread

Posting Permissions

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