HttpSessionBindingListener in practice

xiaoxiao2021-03-06  80

HttpSessionBindingListener is an interface that inherits the Object of this interface, which will be easily called in which the object is easy to call the object, the Object is easybound () Import javax.servlet. *; Import javax.servlet.http. *; Public class UseridWrapper implements HttpSessionBindingListener {public String userid = "default"; public UseridWrapper (String id) {this.userid = id;} public void valueBound (HttpSessionBindingEvent e) {// insert transient user data into the database} public void valueUnbound (HttpSessionBindingEvent e) {// remove transient user data from the database}} // code for doPost () of LoginServletpublic void doPost (HttpServletRequest req, HttpServletResponse res) {String userid = req.getParameter ( "userid"); String password = req. getParameter ( "password");. boolean valid = // validate the userid / password if (valid) {UseridWrapper useridwrapper = new UseridWrapper (userid);. // Sets the UseridWrapper object in the session req.getSession () setAttribute ( " Useridwrapp Er ", useridwrapper;} else {// forward the user to the login page.} ...

转载请注明原文地址:https://www.9cbs.com/read-88841.html

New Post(0)