• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Redirect question

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I have a question regarding redirect. I have noticed that when I do a redirect some (NOT ALL) of my model attributes are passed in the URL. I can't quite understand why. I have some attributes that I want to maintain throughout my controllers so I added the annotation @SessionAttributes with the name of the model attributes. In all my controllers, I use at least two of those session attributes but I can only see this particular one always being passed. If I update one of those session attributes, it gets passed on the URL as well. The one that ALWAYS gets passed in my URL is a String. Other types of objects don't get passed in my URL. Is that the reason? If it's a string and/or if I just updated the attributes that is a string, will it get passed in my URL? I redirect using strings. I also use Apache Tiles.

Thanks in advance for the clarification.

 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

By default all model attributes are considered to be exposed as URI template variables in the redirect URL. Of the remaining attributes those that are primitive types or collections/arrays of primitive types are automatically appended as query parameters.



Take a look at RedirectAttributes I commented on them a bit here

https://coderanch.com/t/571197/Spring/pass-cookies-java-spring#2601860

and here

https://coderanch.com/t/590033/Spring/return-ModelAndView-redirect#2687064

You can find the java doc here:
http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/web/servlet/mvc/support/RedirectAttributes.html

Unlike other redirect attributes, which end up in the target redirect URL, flash attributes are saved in the HTTP session (and hence do not appear in the URL). The model of the controller serving the target redirect URL automatically receives these flash attributes after which they are removed from the session.



See more in the documentation here:
http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/htmlsingle/spring-framework-reference.html#mvc-flash-attributes

 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic