引用
sunchongss 的 jsp注销登陆的代码
login.jsp
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>login</title>
</head>
<body bgcolor="#ffffff">
<h1>管理员登录</h1>
<form method="post" action="check.jsp">
<br>请输入你的账号 : <input name="user_id"><br>
<br>请输入你的密码 : <input name="user_pass"><br>
<br><br>
<center><input type="submit" name="Submit" value="登录" >
<input type="reset" value="清除"></center>
<br>
</form>
</body>
</html>
check.jsp
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>
test
</title>
</head>
<body bgcolor="#ffffff">
<h1>
JBuilder Generated JSP
</h1>
<%
String path = "login.jsp";
if(request.getParameter("usre_name").equals("yourname")){
session.setAttribute("usre_name",request.getParameter("usre_name"));
path = "success.jsp";
}
else
{
session.invalidate();
path = "login.jsp";
}
response.sendRedirect(path);
%>
</body>
</html>
success.jsp
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>
success
</title>
</head>
<body bgcolor="#ffffff">
<jsp:useBean id="cardBeanId" scope="session" class="webapp.cardbean" />
<h1>登陆成功</h1>
<%
if(session.getAttribute("usre_name")==null)
{
response.sendRedirect("errorlogin.jsp");
}
else
{
out.write("你的名字是:"+session.getAttribute("usre_name")+"<br>")
out.write("<a href= \"logout.jsp\"> 注销</a><br>");
}%>
</body>
</html>
loout.jsp
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>
logout
</title>
</head>
<body bgcolor="#ffffff">
<%session.invalidate();%>
<h2>你已经退出,请</h2><a href= "login.jsp"> 重新登录</a>
</body>
</html>
如果是cookies的话就response.cookies(cookiesname)=""
session的话就session.abandon()
注销登陆后,不能后退到以前的页面
Response.Write("<script language=javascript>window.location.replace('Login.aspx')</script>");