• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts Design Question?

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to populate some lists of data used in most of my user forms, this data comes from a database and is fairly static. Where in a struts application is the best place to 1) query the database, I need these lists before showing any Jsp's and 2) Where should these list be stored so they are availible to all users? Thanks for any help.
Cheers
Randy
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Randy,
You want to store that data in application scope. I would suggest calling a class/method to get the data from the servlet's init method. That way the first user doesn't have to wait for the database.
 
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Randy..

To query the database you can go for a new Layer in applicatiopn called DAO.

See J2EE design pattern for DAO.

and regarding storing your data either you can store the m in application scope Or you can follow an approach of creating singleton class, if your data is not changing very frequently.

We have achieved this in our appication. We have created one singleton class.

And we are only passing key value to method and getting a DTO and same time we cache the same data to avoid call to database if same key is requested next time.
 
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Its better as stated above u retrive the data from DB in any intialisation servlet by using init() method and place it in application scope there after .so that its not necessary to query for the first time which will reduce the preformance.......

This is okay if the data is same for all the users or else ite better to keep the data in session
 
Jeanne Boyarsky
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would have the init method call the DAO that Shailesh suggested.
 
The first person to drink cow's milk. That started off as a dare from this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic