• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

How should I store an object in Spring MVC to use in multiple pages?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am creating a shopping cart application to learn Spring MVC. I want to display list of all categories(ex:Mobiles,Books,Stationery,Movies) and subcategories(Ex:iPhone,Motorola under Mobiles) in more than one page. i.e; Home Page, Products page, Category page.

I want to display this category and subcategories list in the header of my application so that I can use these in all the pages.(like below image)



In the Home Page controller I am retrieving the list of categories,subcategories and featured products and passing them to the home page.



I have 2 questions:

1.How can I store the object categoryMap in Spring to access it in multiple pages??


2. I have done the same project using JSP and Servlets and I have stored the categoryMap in application scope so that I can use it in multiple pages. Is this a right approach ? If not how can I do this in a better way ?

Please help!! Thanks
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can create a reusable fragment and include that in all your pages.

That reusable fragment would fetch the categories and sub categories and cache it locally for sometime and refresh the cache on demand.
 
reply
    Bookmark Topic Watch Topic
  • New Topic