java - SessionListener for session modification in Tomcat -
i looking way monitor kind of data stored in sessions. know there session listener has methods called when session created or destroyed session modification? there listener run when data in sessions in modified, ex. when adding new value or modifying old one?
you need implement httpsessionattributelistener , add entry web.xml . has methods attrubuteadded,attrubuteremoved , attrubutereplaced.
public class myattributelistener implements httpsessionattributelistener { @override public void attributeadded(httpsessionbindingevent event) { string attributename = event.getname(); object attributevalue = event.getvalue(); system.out.println("attribute added : " + attributename + " : " + attributevalue); } @override public void attributeremoved(httpsessionbindingevent event) { string attributename = event.getname(); object attributevalue = event.getvalue(); system.out.println("attribute removed : " + attributename + " : " + attributevalue); } @override public void attributereplaced(httpsessionbindingevent event) { string attributename = event.getname(); object attributevalue = event.getvalue(); system.out.println("attribute replaced : " + attributename + " : " + attributevalue); } }
add entry web.xml this
<web-app ...> <listener> <listener-class>com.myapp.myattributelistener</listener-class> </listener>
Comments
Post a Comment