Help coderanch get a
new server
by contributing to the fundraiser
  • 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

How to load resources from my own file in struts

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I am newbee to struts. Instead of ApplicationResources.properties file i would like 3/4 different files to be parsed and loaded into memory when my Tomcat starts up. How can this be acheived in struts?? Where do I write code for this???
Cheers
Jayram
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at this:
http://jakarta.apache.org/struts/api-1.0/org/apache/struts/util/package-summary.html#doc.Messages
 
jayram
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok i will rephrase my question ..
if i want to do certain tasks only once at startup how do i define them under struts
 
Sheriff
Posts: 17652
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've never tried this but it would be one thing I might try if I had to do what you're asking.
Subclass ActionServlet and override the init() method to load the other properties files as ResourceBundles and keep these as private members (of course, I'd call super.init() before anything else). I would also look into whether it would be more appropriate to override one of the initXXX() support methods of ActionServlet.init() to make the specialization more fine-grained.
Then make any necessary changes to struts-config.xml and other startup files.
HTH,
Junilu
 
jayram
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well i extended the class as MyActionServlet and now init() method is overridden. Now i get the following exception when i try to execute.
javax.servlet.ServletException: Cannot find message resources under key org.apache.struts.action.MESSAGE
Any ideas?
Cheers
Jayram
 
Junilu Lacar
Sheriff
Posts: 17652
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you remember to call super.init() ?
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another option is to write a servlet that performs the startup tasks you need, and then put it into your web.xml and set it to run at start-up.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jayram, I'd suggest examining Struts Plugins. Im my opinion they are the best option for your task. Anything you would like to load on startup can be done so using a plugin. They are called whenever the container starts the web application.
Selim
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
FYI, the date on these posts are back in 2002...
 
We noticed he had no friends. So we gave him this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic