Monday, August 6, 2012

Java: On login trigger code run after login

Ok so from the title you can see I am hanging around the database for way to long.

I needed to have some code executed when I logged on so this is what I did:

I threw together a quick HttpSessionListener like such:

package za.co.test.web.faces.listener;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

public class LoginSessionListener implements HttpSessionListener
{
 @Override
 public void sessionCreated(HttpSessionEvent event) {
 doSomeStuff();
 }

@Override
public void sessionDestroyed(HttpSessionEvent event)
{
// do nothing
}
}




Then added the listener to my web.xml.


<listener>
<listener-class>za.co.test.web.faces.listener.LoginSessionListener</listener-class>
</listener>



All working and sorted.

No comments:

Post a Comment