• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts Design Question?

 
Randy Trover
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • 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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34965
377
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • 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.
 
sreenath reddy
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
  • 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
Marshal
Posts: 34965
377
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would have the init method call the DAO that Shailesh suggested.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic