1

Im trying to write a listener that gets the current URL from the user before the session timeout. I need to store this url in the database.

public class SessionTimeoutListener implements HttpSessionListener,SessionAware {

HttpServletRequest request;

@Override
public void sessionDestroyed(HttpSessionEvent event) {


    String url = request.getRequestURL().toString();
// url is empty here!!
    }

@Override
public void sessionCreated(HttpSessionEvent arg0) {

}

@Override
public void setSession(Map<String, Object> arg0) {
    session=arg0;
  }
}

Im new to struts2 and java programming.... i cant understand why i get a null value in that line. Do i have to set the url some where for me to get it as shown? or is the listener itself not correct??

rr87
  • 185
  • 5
  • 18
  • HttpSessionListener is not aware of HttpServletRequest.http://stackoverflow.com/questions/953572/how-can-i-get-httpservletrequest-when-in-an-httpsessionlistener – kosa Sep 06 '12 at 20:59
  • @Nambari Hmm is there another way i can get the url info here itself?? – rr87 Sep 06 '12 at 21:08
  • I don;t think so. Even I am surprised that you didn't get NullPointerException there because request is null. – kosa Sep 06 '12 at 21:11
  • This is not Struts2 interceptor.. SessionTimeoutListener is [event listener](http://docs.oracle.com/cd/B14099_19/web.1012/b14017/filters.htm#i1000654)... It's not same thing... – PrimosK Sep 06 '12 at 21:13
  • @Nambari Can you give me a code example of how to write this as a filter? im really new and a step by step would be great! – rr87 Sep 06 '12 at 21:14
  • http://viralpatel.net/blogs/tutorial-java-servlet-filter-example-using-eclipse-apache-tomcat/ – kosa Sep 06 '12 at 21:15

0 Answers0