You can set the combo box data retrieved from a database as a Servlet
context attribute and retrieve this attribute in your web pages using the
getAttribute method.

Code as follows in your init() method.

getServletConfig().getServletContext().setAttribute("cities", list of
cities....);

And in your JSP page, do a application.getAttribute("cities") and display
it.

Note: Remember to do a load-on-startup of your servlet.

The above approach is fine if you want to have cache within a single
application. If you want to have the same cached data accessible to
different web applications, you can use a Startup class like what Weblogic
provides. You can have your cached data as instance variables of  your
startup class and every web application should be able to access that.

Regards,
Harish.





-----Original Message-----
From: Alex Colic [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 17, 2001 9:15 AM
To: Struts
Subject: how to cache lists?


Hi,

Lets say you have a web app that runs over a number of web pages in a wizard
fashion. On each one of these pages you need to present the user with a
select box holding lists. e.g. locations, cities, etc. This data is read
from a database and rarely changes.

How would you cache these lists so that as each user access this site they
do not need to have this info downloaded again?

I was thinking in the init() of my ActionServlet to access the database and
get these lists then place them in the session with Application scope. I
think this would allow each user to access the data without reaccessing the
database.

Any comments or suggestions are appreciated.

Regards

Alex

Reply via email to