You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Upright Joe <jo...@uprightjoe.com> on 2004/01/27 00:53:43 UTC

Web Applications

Hey everybody, st00pid newbie here... I've gone through the torque 
tutorial successfully and experimented a bit beyond it but now I'm 
trying to use torque in a web application for the first time and have 
run into some trouble.  I'm confused about the Torque.properties file 
and the init() method.  I've placed the Torque.properties file in the 
root of my .war, in WEB-INF/, WEB-INF/classes, WEB-INF/lib, just about 
everywhere, but when I call init("Torque.properties") it can't find it. 
  Where is it supposed to live and how do I reference it?  Also, do I 
call init() in each class that uses Torque or do I need to somehow only 
call it once when the web app is deployed?  Sorry if this is a dumb 
question, but I can't find anything in the docs to help me.  Thanks 
much.

--Travis Hanna


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Re: Web Applications

Posted by Hassan Abolhassani <Ha...@razorfish.co.jp>.
>Hey everybody, st00pid newbie here... I've gone through the torque 
>tutorial successfully and experimented a bit beyond it but now I'm 
>trying to use torque in a web application for the first time and have 
>run into some trouble.  I'm confused about the Torque.properties file 
>and the init() method.  I've placed the Torque.properties file in the 
>root of my .war, in WEB-INF/, WEB-INF/classes, WEB-INF/lib, just about 
>everywhere, but when I call init("Torque.properties") it can't find it. 
>  Where is it supposed to live and how do I reference it?  

My solution is to have an initializer servlet. It passes a phycial path
of the properties file to the init(). Attached is a copy of that servlet
that might be usefull for you. 

You need to make it called when the servlet engine is started. To do
that the following snippet in web.xml of your application will work:

  <servlet>
    <servlet-name>initializer</servlet-name>
    <servlet-class>com.utility.Initializer</servlet-class>

    <init-param>
      <param-name>log4j-property-file</param-name>
      <param-value>WEB-INF/classes/log4j.properties</param-value>
    </init-param>

    <init-param>
      <param-name>torque-property-file</param-name>
      <param-value>WEB-INF/classes/Torque.properties</param-value>
    </init-param>

    <load-on-startup>1</load-on-startup>
  </servlet>

Please note that the servlet also initializes log4j, which you may want
to ignore it.

>Also, do I 
>call init() in each class that uses Torque or do I need to somehow only 
>call it once when the web app is deployed?  Sorry if this is a dumb 
>question, but I can't find anything in the docs to help me.  Thanks 
>much.

You only need to call init() one time.

--Travis Hanna

___

Razorfish Japan, Inc.

アボルハッサニ ハッサン   Hassan Abolhassani  [Technology network]
株式会社 レーザーフィッシュ・ジャパン
Hassan.Abolhassani@razorfish.co.jp
Tel:03-5436-9980 Fax:03-5436-9126