my dog learned polymorphism
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
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Design Question?" Watch "Struts Design Question?" New topic

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.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33130

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1082

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

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

Joined: May 26, 2003
Posts: 33130

I would have the init method call the DAO that Shailesh suggested.
I agree. Here's the link:
subject: Struts Design Question?
It's not a secret anymore!