aspose file tools*
The moose likes Servlets and the fly likes how to create a file on server for ALL clients to use ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to create a file on server for ALL clients to use ?" Watch "how to create a file on server for ALL clients to use ?" New topic
Author

how to create a file on server for ALL clients to use ?

Steve Mutanson
Ranch Hand

Joined: Apr 15, 2003
Posts: 67
When users access servlet "TicketBookingServlet", I want "TicketBookingServlet" to access database and get ALL the information about city names and flight info, then in the picklist I want these values to be poped so users can choose.
However, this requires every session opens database connection, although I can use some connection pooing method to improve the performance. I want to just do this database for ONE time and save the information into a file so that the following client access should read that file. Does this make sense in terms of saving database connection ? If yes, then how can I let my servlet do this ?
Milind Kolapkar
Greenhorn

Joined: Apr 15, 2003
Posts: 2
You can use setAttribute method of ServletContext
and store file in to ServletContext so any message or any session will access it
And plus you can start one daemon thread on server so when ever DB will getupdate it will update that file ....in this way you can save your DB trips...


M I L I N D
Steve Mutanson
Ranch Hand

Joined: Apr 15, 2003
Posts: 67
Originally posted by Milind Kolapkar:
You can use setAttribute method of ServletContext
and store file in to ServletContext so any message or any session will access it
And plus you can start one daemon thread on server so when ever DB will getupdate it will update that file ....in this way you can save your DB trips...

if I choose to use ServletContext and setAttribute on it, where should I put the DB query (only for once) and "setAttribute" code ? should I put in in the "init()" method to do it ?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
Seems to me you want to provide for updating that information on some sort of schedule so using init is not a good idea. After all, your same servlet instance may stay up for weeks.
How about a helper class (JavaBean?) to hold the schedule (or a pointer to the file) and a timestamp indicating when the last real database lookup was. Then if you get a request and the data is no longer fresh you can do a query.
The instance of the helper could be held in the ServletContext as suggested.
Bill
[ April 16, 2003: Message edited by: William Brogden ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to create a file on server for ALL clients to use ?