aspose file tools*
The moose likes Spring and the fly likes Redirect question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Redirect question" Watch "Redirect question" New topic
Author

Redirect question

Gabriela Rios
Ranch Hand

Joined: Feb 27, 2008
Posts: 32
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.

Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1648
    
    7

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

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

and here

http://www.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


[How To Ask Questions][Read before you PM me]
 
Consider Paul's rocket mass heater.
 
subject: Redirect question