I have a login page which asks for username and password. On clicking on login button, web page sends username and password to login servlet as parameters (I am using tomcat). Then, I am creating a session using request.getSession();
I have a sessionListener class (implements HttpSessionListener) where I am overriding sessionCreated() and sessionDestroyed() methods. I have also made listener entry in web.xml file.
My problem is, I want to access the username request parameter inside sessionCreated() method so that I could write the username into mysql database whenever a new session is created.
Basically, is there any way that we can access user entered parameters inside session listeners? Please suggest how can I achieve this.
In your Servlet set the username and password (Obtained from HttpServletRequest) to HttpSession
session.setAttribute("username", uname);
session.setAttribute("password", passwd);
and in your HttpSessionListener get it using
String uname = (String) session.getAttribute("username");
String pwd = (String) session.getAttribute("password");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With