Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve user entered data inside sessionCreated method

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.

like image 282
devm Avatar asked Apr 14 '26 06:04

devm


1 Answers

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");
like image 56
sanbhat Avatar answered Apr 16 '26 18:04

sanbhat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!