Clear @sessionattributes Web site implementation Exit Login

Source: Internet
Author: User

In the website implementation login, I know @sessionattributes, for me is really useful, @SessionAttributes annotations can make the model data stored in the session domain.

This allows the page to jump directly through the ${sessionscope.xxx} to get the user name and other information, very useful.

But today, when I quit logging in, I found a problem, and I cleared the user information in the controller as follows:

@RequestMapping ("/outlogin")    public  String Tologout (HttpSession session, HttpServletRequest request,httpservletresponse response) {        Session.removeattribute ("user");         return "Redirect:/login";    }

But the page can still get user, which makes me very depressed, helpless to help Baidu, see this blog 54666275,

Originally

Spring MVC, before invoking the processing method, automates an implicit model object in the request thread, invokes all methods that have @modelattribute labeled at the method level, and adds the method return value to the implicit model.
Check to see if there is a XXX attribute specified by @sessionattributes ("xxx") in the session, and if so, add it to the hidden model, and if the implied model already has a XXX attribute, the step overrides the attribute value that is already in the implied model. corresponding to the @modelattribute ("xxx") method in the following process if the implied model contains the XXX attribute, assigns it to the parameter, and then populates the parameter object with the request message directly, otherwise if XXX is a session property, That is, the processing class defines the @sessionattributes ("xxx")
Then an attempt is made to get the property from the session and assign its value to the incoming parameter, and then populate it with the request, such as the XXX attribute is not found in the session, and the Httpsessionrequiredexception is thrown.
If the implied model does not have a XXX attribute, and XXX is not a session property, then an object instance that is created into the parameter is populated with the request. @SessionAttributes allows you to specify multiple properties. You can specify multiple properties, such as @SessionAttributes ({"Attr1", "ATTR2"}) by means of a string array. In addition, @SessionAttributes can also specify the Modelmap property to be session by the property type, such as @SessionAttributes (types=User.class), of course, you can also specify multiple classes, such as @sessionattributes (types ={User.class, Dept.class}), you can also use the property name and the property type specified by the union: @SessionAttributes (types ={User.class, Dept.class},value={"Attr1", "ATTR2"}). @SessionAttributes need to clear, use Sessionstatus.setcomplete (); Note that it clears only the @sessionattributes session and does not clear the HttpSession data

Refer to this blog I have made changes

@RequestMapping ("/outlogin")    public  String Tologout (HttpSession session, HttpServletRequest request,httpservletresponse response,sessionstatus sessionstatus) {        Session.removeAttribute ("user");        Sessionstatus.setcomplete ();          return "Redirect:/login";    }

@SessionAttributes need to clear, use Sessionstatus.setcomplete (); Note thatthe Session.removeattribute only clears the @sessionattributes session and does not clear the HttpSession data

Clear @sessionattributes Web site implementation Exit Login

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.