Logut按钮代码并删除会话 [英] Logut button code and remove session

查看:110
本文介绍了Logut按钮代码并删除会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿我想退出并从整个浏览器中删除会话。在我的代码注销按钮中成功重定向到登录页面。但是,当我单击浏览器的后退箭头时,它会指向我之前浏览过的页面。我想这样做..当我点击浏览器中的后退箭头时,它应该保留在登录页面页面上,并且不应该允许使用后退箭头转到其他页面。



这里我的代码



Hey I want logout and remove sessions from entire browser. In my code logout button redirects to login page successfully. But when i click back arrow of the browser it directs to pages which i browsed previously. I want to do this..when i click back arrow in the browser it should stay on the login page page and should not give permission to go to other pages using back arrow.

Here my code

private void logoutSession(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        
	    HttpSession  session = request.getSession();
		try{
			String message = "Logout!";	   
	        session.removeAttribute("loggedUser");  
	        session.invalidate();
			request.setAttribute("loginMsg", message);
			response.sendRedirect(request.getContextPath() + "/login2.jsp");
		}catch(Exception e){
			e.printStackTrace();
		}
	}	





怎么做?提前谢谢!



How to do this? Thank you in advance!

推荐答案

把它放在Logout按钮点击事件...... :)





put this in Logout button click event...:)


if (Session["sessionName"] != null)
       {

           Session.Clear();//clear session
           Session.Abandon();//Abandon session
           Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
           Response.Cache.SetCacheability(HttpCacheability.NoCache);
           Response.Cache.SetNoStore();
           Response.Redirect("yoururl.aspx")

       }


尝试以下..这将放弃会话,并且不允许对您的应用程序进行此操作...







Try the following.. which will abandon the session and will not allow to do which is happening to your application...



Session.Abandon();
      Response.Redirect("Login.aspx");







希望有帮助。




Hope That gona help.


这是你的答案 - 注销后浏览器后退按钮问题 [ ^ ]。
Here is your answer - Browser back button issue after logout[^].


这篇关于Logut按钮代码并删除会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆