• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

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

Posts: 1
  • Mark post as helpful
  • send pies
  • 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
Posts: 3225
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
  • 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.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!