• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Pass variable from one controller to another

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a controller that maps a Post Request.
Taking the input fields some calculations are made and then saved in two variables. I.e  String var1 and String var2.
This Controller redirects to a page using  return new ModelAndView("redirect:/user")
And I have a Controller that maps Get Requests.
In this controller I will need the values var1 and var2, but I do not want to pass them in the URL, as it will be displayed and I need these values to be hidden.

Is there a way to achieve this ? To get those two variables inside the Get Controller so I can pass them as objects in the model.
 
Ranch Hand
Posts: 282
2
jQuery Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Emily Green wrote:I have a controller that maps a Post Request.
Taking the input fields some calculations are made and then saved in two variables. I.e  String var1 and String var2.
This Controller redirects to a page using  return new ModelAndView("redirect:/user")
And I have a Controller that maps Get Requests.
In this controller I will need the values var1 and var2, but I do not want to pass them in the URL, as it will be displayed and I need these values to be hidden.

Is there a way to achieve this ? To get those two variables inside the Get Controller so I can pass them as objects in the model.




Hi Did you with Springs' ModelAttribute to bind values inside a map and send to the next controller as a Param and not  a Request Param?
 
Emily Green
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey. My GET controller Requests Parameter as there's two other parameters that I need to pass.
But I'm not sure how to pass var1 var2 without them passing through the URL. What do you mean by only @Param ? What would that look like ?
modelAndView.addObject("var1",var1) and then how to pass it?
Thank you so much
 
Mohammed Sardar.
Ranch Hand
Posts: 282
2
jQuery Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Emily Green wrote:Hey. My GET controller Requests Parameter as there's two other parameters that I need to pass.
But I'm not sure how to pass var1 var2 without them passing through the URL. What do you mean by only @Param ? What would that look like ?
modelAndView.addObject("var1",var1) and then how to pass it?
Thank you so much



OK, I guess you are on right track. Now you have added var1 using addObject. Now you will return this MNV as a ResponseBody annotation and then access that var1 in your view.  
 
Emily Green
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
return modelAndView; ?

Here's the thing..The controller that has the var1 is the controller that redirects to the other controller.. Which maps for Get for that link.
If I do this :

   ModelAndView modelAndView=new ModelAndView("redirect:/users/");
   modelAndView.add("var1",var1)
   return modelAndView;

The var1 is added in the URL:
       users?var1=var1
And I dont want that. I'm not sure I understood you correctly . Thanks
reply
    Bookmark Topic Watch Topic
  • New Topic