RE: Handling Session Timeout

2003-11-05 Thread Seyhan BASMACI (Internet Yazilimlari Yetkilisi)

try this  :)


public class SessionRequestProcessor extends TilesRequestProcessor{
protected String processPath(HttpServletRequest request,
 
HttpServletResponse response)  throws IOException 
 {

String origPath = request.getRequestURI();

   if(!origPath.endsWith(/Login.do)){

HttpSession session =   request.getSession(false);  // get session 
only if it exists 


  if (session != null ) {// session available, 

  return super.processPath(request, response);  

  }
  
  else// redirect to login page 
  
return /Login; // returns without .do
} 

  else {

  HttpSession session =  request.getSession(false);  // get session only if it 
exists 

  if (session != null)   
  session.invalidate(); 

return super.processPath(request, response);  // process login 
page request

  }

}



-Original Message-
From: Samanth Athrey [mailto:[EMAIL PROTECTED]
Sent: Wednesday, November 05, 2003 5:26 PM
To: [EMAIL PROTECTED]
Subject: Handling Session Timeout


Hello Gurus

I am trying to handle session timeout by extending RequestProcessor. Since
the processPreprocess(...) method is called before the Action.execute(..)
method, am trying to add that piece of code to check if the session is
valid. The problem am facing is, if i return false from this method, the
requestProcessor will stop processing and return the control back to doGet
or doPost method in ActionServlet. How do I redirect it to login.jsp or
index.jsp from there? Any help/tips would be really great.

Thanx.
Sam




-
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: Handling Session Timeout

2003-11-05 Thread Rick Reumann
Samanth Athrey wrote:

I am trying to handle session timeout by extending RequestProcessor. Since
the processPreprocess(...) method is called before the Action.execute(..)
method, am trying to add that piece of code to check if the session is
valid. The problem am facing is, if i return false from this method, the
requestProcessor will stop processing and return the control back to doGet
or doPost method in ActionServlet. How do I redirect it to login.jsp or
index.jsp from there? Any help/tips would be really great.
Rather than do this in a subclass of RequestProcessor, I usually 
have all my Actions extend a Base action (a base DispatchAction 
actually) and in there I override the execute method and do 
something like...

public ActionForward execute(final ActionMapping mapping, final 
ActionForm form, final HttpServletRequest request, final 
HttpServletResponse response) throws Exception {
HttpSession session = request.getSession(false);
if (session == null || session.getAttribute(loggedOut) != 
null ) {
//user doesn't have a session or they loggedOut using the 
logout button
return mapping.findForward(Const.GOTO_LOGIN);
} else if ( session.getAttribute(userBean) == null ) {
//user has a session, but no userBean in scope so therefore 
session has timed out
ActionMessages messages = new ActionMessages();
messages.add(ActionMessages.GLOBAL_MESSAGE, new 
ActionMessage(message.session.expired) );
saveMessages(request, messages);
return mapping.findForward(Const.GOTO_LOGIN);
} else  {
//user is already logged in so
//call super class method which will call apropriate 
dispatch method in subclass
return super.execute(mapping, form, request, response);
}
}

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


RE: Handling Session Timeout

2003-11-05 Thread Caroline Jen
People have suggested servlet filter is a good choice
to check session time-out that if I want all servlets
and JSPs remain intact.

I do not have any idea how it works in Struts.  First
of all, I think this servlet filter has to be declared
in the web.xml.  I have many actions in the struts
application.  How do I call this servlet filter
whenever the flow goes to an action?  Do I code 

HttpSession session = request.getSession( false );
if ( session != null) 
{
   session.removeAttribut( ... );
   session.invalidate();
}

in the doFilter(); ?


--- Seyhan BASMACI (Internet Yazilimlari Yetkilisi)
[EMAIL PROTECTED] wrote:
 
 try this  :)
 
 
 public class SessionRequestProcessor extends
 TilesRequestProcessor{
   protected String processPath(HttpServletRequest
 request,

 HttpServletResponse response)
 throws IOException 
  {
   
   String origPath = request.getRequestURI();
 
if(!origPath.endsWith(/Login.do)){
 
   HttpSession session =  
 request.getSession(false);  // get session only if
 it exists 
 
 
   if (session != null ) {// session
 available, 
 
   return super.processPath(request,
 response);  
 
   }
   
   else// redirect to login
 page 
   
   return /Login; // returns without .do
   } 
 
   else {
 
   HttpSession session = 
 request.getSession(false);  // get session only if
 it exists 
 
   if (session != null)   
   session.invalidate(); 
 
   return super.processPath(request, response); 
 // process login page request
   
   }
   
   }
 
   
 
 -Original Message-
 From: Samanth Athrey
 [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, November 05, 2003 5:26 PM
 To: [EMAIL PROTECTED]
 Subject: Handling Session Timeout
 
 
 Hello Gurus
 
 I am trying to handle session timeout by extending
 RequestProcessor. Since
 the processPreprocess(...) method is called before
 the Action.execute(..)
 method, am trying to add that piece of code to check
 if the session is
 valid. The problem am facing is, if i return false
 from this method, the
 requestProcessor will stop processing and return the
 control back to doGet
 or doPost method in ActionServlet. How do I redirect
 it to login.jsp or
 index.jsp from there? Any help/tips would be really
 great.
 
 Thanx.
 Sam
 
 
 
 

-
 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]
 


__
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree

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