简体   繁体   English

在JSP中使用JavaScript进行会话检查

[英]Session checking using javascript in jsp

I have done session activation and deactivation using servlets using 我已经使用servlet完成了会话的激活和停用

HttpSession s = request.getSession(); 
s.setAttribute("uname", uname);

and deactivation in logout servlet using 和注销注销servlet中使用

HttpSession sess=  request.getSession();
sess.invalidate();

Now I want to check in my JSP page that is session is activate or not? 现在,我要检查会话是否已激活的JSP页面吗?
So for this I want this checking using JavaScript . 因此,为此,我希望使用JavaScript进行检查。 I have method to check this using simple JSP code but I want this using JavaScript's function. 我有使用简单的JSP代码检查此方法的方法,但我想使用JavaScript的函数进行检查。 So that if session is activate then I will reload same page and if session is expired then it will redirect to the login.jsp page. 因此,如果会话被激活,那么我将重新加载同一页面,如果会话已过期,则它将重定向到login.jsp页面。 So I could not get any idea about it. 所以我对此一无所知。

As for tomcat webservers the session is usually mantained by a cookie with name JSESSIONID. 对于tomcat Web服务器,会话通常由名称为JSESSIONID的cookie进行维护。 However from that cookie being set you can not be sure that the session is still valid. 但是,从设置该cookie开始,您不能确定该会话仍然有效。 The only one who can tell you, having a valid session or not is the server. 可以告诉您(是否有有效的会话)的唯一服务器。 So it'll be better to do the redirect on the server. 因此,最好在服务器上进行重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM