#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    28
    Rep Power
    0

    Question Extending Struts Action Class to handle timeouts


    I am using Struts 1.0.2 and I want to put my session timeout code in one place. I am thinking of extending the Action class to do this. But I am not sure if I should override the perform method. If I do I have to return an ActionForward object...

    Any thoughts?
  2. #2
  3. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    If you want to have one central place that everyone can get authorized at, one way would indeed be to extend the action class. What you could do is something like this:
    Code:
    abstract class MyAction extends Action {
      public ActionForward perform(ActionMapping mapping,
         ActionForm form, javax.servlet.http.HttpServletRequest request,
         javax.servlet.http.HttpServletResponse response) {
        ...do some authentication code...
        return myPerform(mapping, form, request, response);
      }
      abstract ActionForward myPerform(ActionMapping mapping,
         ActionForm form, javax.servlet.http.HttpServletRequest request,
         javax.servlet.http.HttpServletResponse response) {
        ..use this as a normal perform method...
      }
    }
    Then, when your code extends MyAction it would implement the myPerform method instead of perform. The ActionServlet will call the perform of MyAction, which will in turn call the myPerform method of the action that extends MyPerform. Hope that made sense.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    28
    Rep Power
    0

    thanks


    Exactly! Thanks!

IMN logo majestic logo threadwatch logo seochat tools logo