The moose likes JSP and the fly likes best way to do in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "best way to do in jsp" Watch "best way to do in jsp" New topic

best way to do in jsp

Sripathi Krishnamurthy
Ranch Hand

Joined: Mar 07, 2005
Posts: 232
There is a combobox in a jsp for which the values will be populated from a database table. This combo box displays different countries available. We know that the country listing dont change very often, but still we are not sure whether any country can be added or deleted.
We dont want to get the data every time from database. But whenever a new country is added or existing country is deleted, immediately the change should be reflected in the jsp page.
we know that we can use a jsp:include and do this. but it will be fetching data everytime from db which I dont like.
If we use a include directive, then insert or delete from the table will not be reflected in the jsp unless a change is done in parent page.
which is the best way to achieve the above requirement?
Sripathi Krishnamurthy
Ranch Hand

Joined: Mar 07, 2005
Posts: 232
one additional information
The combo box will be there in almost all the jsp pages in the website. thats why we plan to make it a included page.
J Singh

Joined: Sep 26, 2005
Posts: 16
Cache the data in a collection, and display from there. Maintain a local file that stores the last DB read date. (app_db_read)

Write a INSERT/ UPDATE/ DELETE trigger that updates the update time in a one column table (country_update), or, updates a file (db_update) on the disk with the new timestamp, when a new country is added/ deleted. I am not sure of triggers can write to system files - read on.

The code that fetches data from the collection compares the date in the local file app_db_read, and the country_update, or, the file that the trigger updated - db_update (if possible), just before reading the collection. If the date is same, data has not changed, continue reading the cached data. If the dates are different, data has changed, update the collection, and read the new data from the collection.

If triggers can write to system files, your problem is solved without a DB call. If not, yes, there is still a DB read call from the country_update table, but thats really a one value update_date fetch unlike a collection of values fetch. And I dont see any other way how a data change at the DB level would be alerted in the application.


[ October 06, 2005: Message edited by: J Singh ]
[ October 06, 2005: Message edited by: J Singh ]
Don't get me started about those stupid light bulbs.
subject: best way to do in jsp
Similar Threads
Acces table
Unable to get the chackbox array values in Servlet file
Enabling links according to user's authorization
Populating dynamic data into fields
what’s the best practice to config Hibernate-Spring for multiple database relationship?