Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Startup

 
Patrick McDonogh
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
By the way this forum is brilliant!
I was wondering if anyone knows how to do the following.
I would like to get some code to run as my struts web application starts before any users request a page.

For instance i would like to put objects into the application scope but they need to be initialised first and some need to get their values from the database.
How do you get a servlet or struts action to run as soon as the application is started?, is what i am asking really.

Also while i am on the subject i see that the servlets and jsps are only compile the first time they are requested.
Is there a way to get these to compile as soon as the application is started rather than waiting for a user to request the page?
Cheers, everyone and thanks for the feedback.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's what I recommend when you need something to run at startup time in a Struts application:
  • Write a class that extends the org.apache.struts.action.Plugin interface
  • Put your initialization logic in the init() method required by the interface
  • Register your plugin in the struts-config.xml file
  • Here is an example of the entry you'd make in your struts-config.xml file:

    If you have properties you'd like to pass to your plugin, you can do so in a <set-property> stanza embedded in the <plug-in> stanza.

    Struts will then call your logic when the application first starts up.
    Also while i am on the subject i see that the servlets and jsps are only compile the first time they are requested.
    Is there a way to get these to compile as soon as the application is started rather than waiting for a user to request the page?

    I work with WebSphere as my application server. It has an option to compile all JSPs when the application is deployed to the server. Many other App Servers have a similar option. Check your App Server Documentation.
     
    Patrick McDonogh
    Ranch Hand
    Posts: 89
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    thanks for the info.

    The plugin idea seems very good.

    Have a great weekend
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic