• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Persisting request variables beyond pageContext

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic