how use and invalidate session in java web? -


in web application, use session store information of user changing, , in database update data @ end of session, use httpsessionlistener , works well, when user logs account,then there data last session, not know what's matter.

when user logs in account:

string name = request.getparameter(attribute.attribute_username);     string password = request.getparameter(attribute.attribute_password);     string page;     user user;     try {         user = userservice.find(name, password); //i data database     } catch (serviceexception e) {         log.error("exception occurred in login command ", e);         request.setattribute(attribute.attribute_error_message, messages.unknown_error);         return pagepath.page_info;     }      httpsession session = request.getsession(true);     session.setattribute(attribute.attribute_user, user);     page = "controller?command=gotohome";      return page; 

and sessionlistener:

public class userlistener implements httpsessionlistener {     public void sessiondestroyed(httpsessionevent e) {         httpsession session = e.getsession();         user user = (user) session.getattribute(attribute.attribute_user);         daofactory factory = new mysqldaofactory();         userservice userservice = new userserviceimpl(factory.getuserdao());         userservice.update(user);         session.removeattribute(attribute.attribute_user);     } } 


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -