What is the difference between the following methods?

2

I'm developing an application in JSF and I came across the following methods and want to know the difference between them.

((HttpSession)FacesContext.getCurrentInstance()
                     .getExternalContext().getSession(false)).invalidate();

and

FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
    
asked by anonymous 29.03.2015 / 19:03

1 answer

2

The two code snippets perform the same action, which is to invalidate a session.
The difference is in what class comes the method. invalidate is from class HttpSession , invalidateSession is of class ExternalContext . Note that in the code snippet that you use invalidate you are doing a casting session retrieved from FacesContext to HttpSession so that you can access the method. It is interesting to add that the implementation of invalidateSession will only execute invalidate of HttpSession .

    
18.04.2015 / 05:53