How to get data from database in the begining

Hi

I am using JSF + some DB in my project. I am trying to do more than just a web app. I can get the page data from the database at any time because user would click on it.

What I want to do is, At the start of the tomcat server, I would like to fetch some data and send the data to some other processes. What are the best ways to do that?

Do I need need to write a servlet and write just the init method ?

at the same time, the JSF application should also use the same connection to update any page date.

thanks

[550 byte] By [vpalkondaa] at [2007-11-26 21:48:44]
# 1

You could use the load-on-startup tag in your project's web.xml , to start the Servlet that loads all the initial data from the database.

This explains load-on-startup

http://mail-archives.apache.org/mod_mbox/struts-user/200312.mbox/%3C02a401c3b987$c3b701a0$65fea8c0@kurtosys%3E

Say the Servlet loads data into a JavaBean or a list of JavaBeans, then other classes could read from the JavaBean or list of JavaBeans loaded by the Servlet.

I've just begun learning JSF so I can't really help with the JSF part.

appy77a at 2007-7-10 3:39:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
thanks, but it requires to write another servlet. Can I get away with that ...Can I get same behavior in the JSF
vpalkondaa at 2007-7-10 3:39:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Probably I'm too new to JSF to tell :-( , may be someone else might know better....
appy77a at 2007-7-10 3:39:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Juse use the constructor or init blocks of the backing bean. Or maybe the getter of the datatable valuebinding if you want to handle it more specific.This might give you some insights: http://balusc.xs4all.nl/srv/dev-jep-dat.html
BalusCa at 2007-7-10 3:39:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

thanks for the link.

But the problem is the backing bean gets invoked only when the user does something on JSF pages.

But my problem is what if the user does not bring the up th web page.

I want to retrieve the data when the tomcat starts and send it over to some other process like when booting a device....

The only thing the JSF servlet starts when the tomcat starts. But I cannot init in the JSF servlet. I was wondering if there is any way that servlet notifies an object when it starts. So that I can init the data

vpalkondaa at 2007-7-10 3:39:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
You can use more than one backing bean in the webapp.
BalusCa at 2007-7-10 3:39:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
Sorry I didn't get that ..Correct me if I am wrong..Backing beans are used to tie a UI component.when UI component is not invoked then how would the baking bean gets initialized?thanks
vpalkondaa at 2007-7-10 3:39:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
I think we can add ServletContextLisener, which would get invoked when servlet is init. So I guess I can do the magic at that time
vpalkondaa at 2007-7-10 3:39:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...