wood burning stoves*
The moose likes Struts and the fly likes Struts Design Question? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Design Question?" Watch "Struts Design Question?" New topic
Author

Struts Design Question?

Randy Trover
Ranch Hand

Joined: Feb 26, 2001
Posts: 34
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30353
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

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.


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
sreenath reddy
Ranch Hand

Joined: Sep 21, 2003
Posts: 415
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30353
    
150

I would have the init method call the DAO that Shailesh suggested.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Struts Design Question?