You can also do this by sub classing all your actions from a base action of
some sort.
This would allow for better code reuse.


BaseAction.java
----------------
import org.blah.blah.blah.Something


abstract public class BaseAction extends Action{

...
...
  abstract public ActionForward doPerformOrExecute( ActionMapping mapping,
                              ActionForm form,
                              HttpServletRequest request
                             )
...
...
// perform or execute - depending on your version

  public ActionForward perform(ActionMapping mapping,
                               ActionForm form,
                               HttpServletRequest request,
                               HttpServletResponse response)
    throws IOException,
           ServletException
  {
...
...
try{
  //calling my own abstract method
  this.doPerformOrExecute(mapping, form, request);

}
catch (Exception e) {
        //I've also seen these broken out by every conceivable exception with
private handler methods for each case.
          log.debug("Oh crap!!!");
     //     e.printStackTrace();
}
//could do finally or just let it flow

closeConnexion();

return mapping.findForward("success");
...
...
...




Having abstract base actions has cut out a lot extra overhead in all of my
struts projects.

Good Luck!
JM







> -----Original Message-----
> From: Malcolm Dew-Jones [mailto:[EMAIL PROTECTED]]
> Sent: Friday, May 03, 2002 3:05 PM
> To: Struts Users Mailing List
> Subject: Q: how do I do something after a forward?
>
>
>
> In my action class I want to prepare some things and then forward to a JSP
> to display those things. However, I also want to do some cleanup after the
> JSP has finished.
>
>
> Want I want is conceptually the same as
>
>    public final class myAction report extends Action
>    {
>       public ActionForward perform(...)
>       {
>               dbh = get_database_connection()
>               initialize_some_beans( dbh , other , stuff );
>
>               try
>               {
>                 return (mapping.findForward("success"));
>               }
>               finally
>               {
>                 close_connection_no_matter_what();
>               }
>       }
>   }
>
> Obviously the above does not work.
>
> Is there a way for the myAction class to ensure that the database
> connection is closed after the JSP is done, or must the JSP do this?
>
>
> --
> To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
>
>


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

Reply via email to