myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jon Harley" <J.W.Har...@warwick.ac.uk>
Subject RE: Redirect on Session Timeout
Date Thu, 07 Jul 2005 12:09:13 GMT

I suggest you are applying the filter to login.jsf!

Better add a clause to your if statement to check that the requested page is not login.jsf
before you send a redirect to login.jsf.

Jon

_________________________________________________________________
Dr JW Harley                                  Senior Technologist
E-lab, IT Services Department, University of Warwick, Coventry UK
<J.W.Harley@warwick.ac.uk>    www.warwick.ac.uk/staff/J.W.Harley/

>>> Rashmi.Kumari@rmsi.com 07/07/05 07:35AM >>>

Hi,

I did the same thing to check for an invalidated session. But when session
becomes null, infinite loop is formed
and the output string "Session is null" is getting printed infinite times.


public void doFilter(ServletRequest request, ServletResponse response,
      FilterChain chain) throws IOException, ServletException
 {
      System.out.println("LoginBean.client = " + LoginBean.client);
      if (((HttpServletRequest)request).getSession(false) == null &&
                                                      (LoginBean.client !=
null))
      {
        System.out.println("session is null");
         ((HttpServletResponse)response).sendRedirect("/login.jsf");
      }
      else
        chain.doFilter(request, response);
  }

Please suggest where I am doing wrong.

Regards,

Rashmi



                                                                                         
                                       
                    "Daniel                                                              
                                       
                    Murley"              To:     "'MyFaces Discussion'" <users@myfaces.apache.org>,
"'Adrian Merrall'"           
                    <dmurley@neura        <pigeonracer@gmail.com>               
                                                
                    genix.com>           cc:                                          
                                          
                                         Subject:     RE: Redirect on Session Timeout    
                                       
                    07/07/2005                                                           
                                       
                    09:07 AM                                                             
                                       
                    Please respond                                                       
                                       
                    to "MyFaces                                                          
                                       
                    Discussion"                                                          
                                       
                                                                                         
                                       
                                                                                         
                                       




Ahh great!  Worked a treat.

Thanks,

Daniel

-----Original Message-----
From: Adrian Merrall [mailto:pigeonracer@gmail.com] 
Sent: Thursday, 7 July 2005 12:45 PM
To: MyFaces Discussion
Subject: Re: Redirect on Session Timeout

On 7/7/05, Daniel Murley <dmurley@neuragenix.com> wrote:
> Hi,
>
> Read a post here recently showing the following for performing a
> redirect for session timeouts/invalidation.
>
> This was :
>
> public void doFilter(ServletRequest request, ServletResponse response,
>        FilterChain chain) throws IOException, ServletException {
>    if (((HttpServletRequest)request).getSession(false) == null)
>    {
>      request.getRequestDispatcher("/faces/jsp/login.jsp").
>        forward(request,response);
>    }
>
>    chain.doFilter(request, response);
> }
>
>
> However the chain.doFilter causes an IllegalStateException.  (This is
> under Jboss 4.0.2).  Is this expected behaviour, or is there a way to
avoid it?

Try putting an "else" around the chain.doFilter() as it may be executed
anyway, ie. do the forward _or_ the chain.  I presume the illegal state
exception is being caused when there is no session.  BTW would you want to
do a forward or a response.sendRedirect() in this circumstance?

HTH
Adrian







Mime
View raw message