java - How to commit an object from a get controller to a post controller? -


how transmit object controller post controller without using input fields on jsp side?

@requestmapping(value = "/benutzerverwaltung/{benutzerid}/kennwort", method = requestmethod.get) public string benutzerverwaltungkennwort(@pathvariable("benutzerid")int id, @modelattribute("benutzer") cbenutzer benutzer, model model){     benutzer.getbenutzer(id);     benutzer.setpasswort(null);     //code transmit?     return "benutzerverwaltung/kennwort"; } 

and second controller should object benutzer

@requestmapping(value = "/benutzerverwaltung/{benutzerid}/kennwort/aendern", method = requestmethod.post) public string benutzerverwaltungkennwortgo(@pathvariable("benutzerid")int id, @modelattribute("benutzer") cbenutzer benutzer, model model){     //here need object attributes controller above...     system.out.println(benutzer.tostring()); //what attributes = null -.-     return "redirect:/benutzerverwaltung/"; } 

someone out there got idea? reading

you need either use httpsession attributes or flash attributes (which use httpsession anyway). use flash attributes, spring makes available redirectattributes class. in handler

@requestmapping(value = "/benutzerverwaltung/{benutzerid}/kennwort", method = requestmethod.get) public string benutzerverwaltungkennwort(@pathvariable("benutzerid")int id, @modelattribute("benutzer") cbenutzer benutzer, model model, redirectattributes redirectattrs){     benutzer.getbenutzer(id);     benutzer.setpasswort(null);     redirectattrs.addflashattribute("benutzer", benutzer);     return "benutzerverwaltung/kennwort"; } 

from javadoc:

after redirect, flash attributes automatically added model of controller serves target url.

this true if didn't perform redirect, ie. in next request.

note these flash attributes available in next request make (flash!). if aren't sure if next request post need, should save object directly in httpsession.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -