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

Persisting request variables beyond pageContext

Anthony Andras
Ranch Hand

Joined: Nov 09, 2008
Posts: 31
Hi guys,

I am very new to Spring and am trying to figure out the API. I have the following controller class defined:




When my post method is called, it forwards it on to the confirmSubmission page. Essentially what I want to do is take my submission object and preserve it for the next forward (ex: when a user clicks "confirm" on the next page, I don't want force spring to reconstruct the object, I would like to instead just use the object that was constructed here). Is there any way I can do this? I looked into the BindingResult API and tried a few things that didn't work.

Basically, I want to prevent myself from having to write the code at line 3 in the snippet below:





Anthony
Anthony Andras
Ranch Hand

Joined: Nov 09, 2008
Posts: 31
I want to update the thread as I figured out the answer to this question. As it turns out, when you use the RequestMapping annotation, the method that is assigned as the "RequestMapper" can actually take in a parameter that represents the HttpSession. Essentially, the signature of the method would look something like this:



One then can set attributes into the HttpSession which then acts as a cache for a particular user. I honestly feel awkward using the session as a cache. Does anyone have an idea of better caching strategies? One idea that originally crossed my mind from prior experience was to cache these variables in the service layer. However, this presents an issue since spring treats services as singletons: you end up with concurrency issues with this approach. Any input / advice would be greatly appreciated.

Thanks!

Anthony
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Persisting request variables beyond pageContext