session.removeAttribute 在 Java 中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27400747/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 04:17:21  来源:igfitidea点击:

session.removeAttribute doesn't work in java

javajspservlets

提问by Himanshu Sethi

I am removing a session through session.removeAttribute(attribute_name);. But through this session attribute is not removed actually. How can I remove a particular session attribute? Please help me!

我正在通过session.removeAttribute(attribute_name);. 但是通过这个会话属性实际上并没有被移除。如何删除特定的会话属性?请帮我!

Thanks

谢谢

回答by meteorzero

In order to remove/delete session completely, use session.invalidate()method. If you just want to remove a particular attribute then use session.removeAttribute(attribute_name)but make sure attribute_name is right and not null.

为了完全删除/删除会话,请使用session.invalidate()方法。如果您只想删除特定属性,请使用session.removeAttribute(attribute_name)但请确保 attribute_name 正确且不为空。

回答by ANKIT CHOPADE

Just add following code in your jsp file

只需在您的 jsp file

i am sure this will do if not ping me

如果不ping我,我相信这会做

 response.setHeader("cache-Control","no-cache,no-store,must-revalidate"); 
 response.setHeader("Pragma","no-cache");    
 response.setHeader("Expires","0");