本文介绍了无法在JSP中使用JavaScript清除会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用servlet在login.jsp页面上创建会话
created session from login.jsp page using servlet
String msg = "";
HttpSession sess = request.getSession();
// if(sess != null)
//sess.invalidate();
if (sess.getId() != null) {
sess.setAttribute("uname", uname);
sess.setAttribute("pwd", pwd);
}
使用其他psp页面检索会话
retrived session in other jsp page using
<b> Welcome ${uname}</b>
注销超链接
<a href="login_ml.jsp" id="logout_link" onclick='lgt()'>Logout</a></td>
javascript清除会话
javascript to clear session
function lgt(){
var logout = document.getElementById("logout_link");
logout.session.clear();
alert("logout");
}
推荐答案
我们无法直接从JS代码清除会话.您必须调用另一个JSP页面将使该会话无效:
We cannot clear session directly from JS code . You have to call another JSP page will invalidate that session :
Javascript函数:
function destroySession() {
window.location = "killSession.jsp";
}
killSession.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Log out</title>
</head>
<body>
<%
session.invalidate();
%>
User has been Logged out sucessfully!!!!
</body>
</html>
这篇关于无法在JSP中使用JavaScript清除会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!