RE: No Way to Put the init() Method Inside the ActionForward Execute( ... ) Method
Why can't you call the init() method from inside the execute() method (at the beginning of it )? Anna From: Caroline Jen [mailto:[EMAIL PROTECTED] Sent: Fri 17/09/2004 2:06 PM To: [EMAIL PROTECTED] Subject: No Way to Put the init() Method Inside the ActionForward Execute( ... ) Method 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]
RE: No Way to Put the init() Method Inside the ActionForward Execute( ... ) Method
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 com.xxx.xxx.servlet.InitServlet log4jProperties conf/log4j.properties 3 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]
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]