aspose file tools*
The moose likes Struts and the fly likes Startup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Startup" Watch "Startup" New topic
Author

Startup

Patrick McDonogh
Ranch Hand

Joined: Oct 13, 2005
Posts: 89
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

Joined: Feb 15, 2005
Posts: 4864
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.


    Merrill
    Consultant, Sima Solutions
    Patrick McDonogh
    Ranch Hand

    Joined: Oct 13, 2005
    Posts: 89
    thanks for the info.

    The plugin idea seems very good.

    Have a great weekend
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Startup
     
    Similar Threads
    Generate select menu from database
    HELP ME (URGENTLY)
    Dynamically setting the contentType in Struts.
    JSF page properties on user request
    How to restrict direct accessing .jsp and .do in struts webapp