aspose file tools*
The moose likes Struts and the fly likes Struts init() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts init()" Watch "Struts init()" New topic
Author

Struts init()

Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
Hi

Am new to struts. I like to know where to load the properties file.. In servlet we have init() to load the properties. Similarly please suggest me where to load in Struts
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

You can load it in the constructor...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
Constructor ?. Which Constructor ?.

I guess better option is to extend the Action Servlet

After extending in the web.xml

<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>

Instead ActionServlet I configured my servlet I mean suclass of ActionServlet, am unable to start tomcat. Please help
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

No, ActionServlet should almost never need to be modified.

What kind of properties are you trying to load? Why not do it outside of the Struts framework in an application context listener or initialization servlet? If you *must* do it in Struts, use a plugin.
Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
I just extended the TilesRequestProcessor and added my property file loading and log file initialization in the init() and everything works fine.

Modified struts-config.xml

Instead of <controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>

added
<controller>
<set-property property="processorClass" value="MyProcessor"/>
</controller>

Could you please tell me whether am on the rite path.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Not really--why change something you don't have to when there are already mechanisms in place that don't require work elsewhere?
Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
Please assist me, where I can place this code.

Some application specific properties and log initialization file creation.. etc.. I need do to these things in application startup.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

What was wrong with the suggestions I already gave?

(And what log file configuration are you doing? Why not just let the logging framework handle that?)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts init()
 
Similar Threads
How to use Properties file contents
ResourceBundle.getBundle
load on startup tag
Having problems reading a file from servlet in Windows XP with Tomcat
Load a configuration file