• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Startup

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    thanks for the info.

    The plugin idea seems very good.

    Have a great weekend
    reply
      Bookmark Topic Watch Topic
    • New Topic