Why not write an InitServlet that is set to initialize prior to the struts
ActionServlet in web.xml?  This could override the init() method and provide
the services you need.

>From web.xml
    <!-- Init Servlet - loads logging (log4j) -->
  <servlet>
    <servlet-name>init</servlet-name>
    <servlet-class>com.xxx.xxx.servlet.InitServlet</servlet-class>
        <init-param>
           <param-name>log4jProperties</param-name>
           <param-value>conf/log4j.properties</param-value>
        </init-param>
     <load-on-startup>3</load-on-startup>
  </servlet>

Then your init() method could have something like:
        public void init() {
                realPath = getServletContext().getRealPath("/");
                initLogging();
                initDataSource();
                etc...
        }
-----Original Message-----
From: Erik Weber [mailto:[EMAIL PROTECTED] 
Sent: Friday, September 17, 2004 12:40 PM
To: Struts Users Mailing List
Subject: Re: No Way to Put the init() Method Inside the ActionForward
Execute( ... ) Method


I would write a Struts Plug-In (very easy) and initialize the 
"smtpServer" variable (and similar variables) there, making the 
configured value available to the rest of the application (including 
your Actions) by setting an Application scope attribute (this also 
abstracts the configuration so that in the future you might configure it 
in a properties file or source file instead of web.xml).

For example:

form.getServlet().getServletContext().getAttribute("smtpServer");


Erik


Caroline Jen wrote:

>We cannot put a method inside another method.
>
>When using the Struts, we start with:
>
>public final class MyClass extends Action
>{
>    public ActionForward execute( ActionMapping
>mapping,
>            ActionForm form,
>            HttpServletRequest request,
>            HttpServletResponse response )
>        throws java.lang.Exception
>    {
>
>        .......
>        .......
>
>    }
>}
>
>I have a void init( ...) { ... } method shown below.
>Of course, I cannot put this init( ... ) inside the
>ActionForward Execute( ... ) { ... }
>
>What am I supposed to do?  Do I put this void init(
>... ) { ... } method before the ActionForward Execute(
>... ) { ... } begins?
>
>Code:
>=================================================
>       String smtpServer;
>  
>       public void init(ServletConfig config) throws ServletException
>       {
>          super.init(config);
>          smtpServer =
>config.getInitParameter("smtpServer");
>       }
>=================================================
>
>
>       
>               
>__________________________________
>Do you Yahoo!?
>New and Improved Yahoo! Mail - 100MB free storage! 
>http://promotions.yahoo.com/new_mail
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>  
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to