<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>session1.jsp</title>
</head>
<body>
<%
String cardid = null ;
Cookie[] cks = request.getCookies() ; if(cks != null)
{
// 如果已经设置了cookie , 则得到它的值,并保存到变量pName中
for(int i=0; i<cks.length; i++)
{
if(cks[i].getName().equals("cardid")) cardid = cks[i].getValue();
}
}
%>
<form action="session2.jsp" method="post">
卡号<input type="text" name="cardid" value="<% if(cardid != null) out.println(cardid); %>"><br>
密码<input type="password" name="password"><br>
<input type="submit" value="提交">
</form> </body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>session2.jsp</title>
</head>
<body>
<%@page import="java.net.URLEncoder"%>
<%@page import="com.shuyinghengxie.bank.CardDAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
//设置不缓存页面
response.setHeader("Cache-Control", "no-cache") ; //登陆成功定时跳转
//response.setHeader("refresh", "2;URL=http://www.baidu.com") ; //页面跳转
//response.sendRedirect("success.jsp") ; String kahao = request.getParameter("cardid") ; String password = request.getParameter("password") ; if(kahao==null || password==null ||
kahao == "" || password == "" )
{
out.write("请正确登录") ;
}
else
{
CardDAO cd = new CardDAO() ; if(cd.checkLogin(kahao, password))
{
//out.write("登陆成功") ;
response.getWriter().write("验证通过") ; //创建Cookie
Cookie ck = new Cookie("kah888o",kahao) ; //设置过期时间
ck.setMaxAge(10*24*60*60) ; //发送
response.addCookie(ck) ; //创建session
session.setAttribute("kahao", kahao) ;
session.setAttribute("username","李四") ; //设置session超时时间
//默认设置是20分钟
//如果超过20分钟没有任何请求发送给服务器,session就失效
session.setMaxInactiveInterval(30) ; response.sendRedirect("session3.jsp") ; }
else
{
out.write("登录失败") ;
}
} %>
</body>
</html>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>session3.jsp</title>
</head>
<body>
<%
Object kahao = session.getAttribute("kahao") ; if(kahao != null)
{
out.write("您已登陆") ;
}
else
{
out.write("尚未登陆") ;
}
%>
<a href="session4.jsp">退出登录</a>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!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=UTF-8">
<title>session4.jsp</title>
</head>
<body>
已退出!
<% session.invalidate() ; //销毁session //2秒后跳转
response.setHeader("refresh","2 ; url= session3.jsp") ; %> </body>
</html>

这时点击退出,跳到session4页面,此页面定时2秒跳转session3

这是可以看到已退出登陆

session 登陆浏览,并实现session注销登陆的更多相关文章

  1. 如何实现免登陆功能(cookie session?)

    Cookie的机制 Cookie是浏览器(User Agent)访问一些网站后,这些网站存放在客户端的一组数据,用于使网站等跟踪用户,实现用户自定义功能. Cookie的Domain和Path属性标识 ...

  2. [转]mvc3 使用session来存储类来存储用户登陆信息

    mvc3 使用session来存储类来存储用户登陆信息 2013-08-26 09:48:56|  分类: NET开发 |举报 |字号 订阅   项目之前的登陆机制是这样的:用户登陆后初始化一个类,类 ...

  3. php ecshop 二级域名切换跳转时session不同步,解决session无法共享同步导致无法登陆或者无法退出的问题

    echshop基础上做了单点登录的 一级域名与二级域名 退出时 清空session 都是一级域名的session 因为二级域名的session是设置在二级域名上的 echshop基础上没有做单点登录的 ...

  4. 在IIS上发布项目后浏览时报的错:Unable to make the session state request to the session state server

    错误描述: Unable to make the session state request to the session state server. Please ensure that the A ...

  5. IOS开发之记录用户登陆状态,ios开发用户登陆

    IOS开发之记录用户登陆状态,ios开发用户登陆 上一篇博客中提到了用CoreData来进行数据的持久化,CoreData的配置和使用步骤还是挺复杂的.但熟悉CoreData的使用流程后,CoreDa ...

  6. {Django基础八之cookie和session}一 会话跟踪 二 cookie 三 django中操作cookie 四 session 五 django中操作session

    Django基础八之cookie和session 本节目录 一 会话跟踪 二 cookie 三 django中操作cookie 四 session 五 django中操作session 六 xxx 七 ...

  7. 用户登陆状态,ios开发用户登陆

    IOS开发之记录用户登陆状态,ios开发用户登陆 上一篇博客中提到了用CoreData来进行数据的持久 化,CoreData的配置和使用步骤还是挺复杂的.但熟悉CoreData的使用流程后,CoreD ...

  8. ecshop登陆后价格可见,会员注册登陆才能显示价格

    打开模版文件夹里面的goods.dwt 查找{$lang.shop_price}<font class="price" id="ECS_SHOPPRICE" ...

  9. 2016-02-20WebForm登陆验证,判断用户是否登陆 PageBase类

    http://blog.csdn.net/fanbin168/article/details/49404233 很多时候,WebFrom页面,我们需要判断用户是否已经登陆了.假如有很多页面,难道我们要 ...

随机推荐

  1. Hadoop入门实践之从WordCount程序说起

    这段时间需要学习Hadoop了,以前一直听说Hadoop,但是从来没有研究过,这几天粗略看完了<Hadoop实战>这本书,对Hadoop编程有了大致的了解.接下来就是多看多写了.以Hado ...

  2. 【python cookbook】【数据结构与算法】19.同时对数据做转换和换算

    问题:我们需要调用一个换算函数(例如sum().min().max()),但是首先需对数据做转换或者筛选处理 解决方案:非常优雅的方法---在函数参数中使用生成器表达式 例如: # 计算平方和 num ...

  3. 【python cookbook】【数据结构与算法】13.通过公共键对字典列表排序

    问题:想根据一个或多个字典中的值来对列表排序 解决方案:利用operator模块中的itemgetter()函数对这类结构进行排序是非常简单的. # Sort a list of a dicts on ...

  4. scala模式匹配

    package com.ming.test /** * 模式匹配 */ object MatchTest { def main(args: Array[String]): Unit = { //mat ...

  5. javaWeb 使用cookie显示上次访问网站时间

    package de.bvb.cookie; import java.io.IOException; import java.io.PrintWriter; import java.util.Date ...

  6. Yeoman

    安装Yeoman之前,确认安装好Node.js和npm. sudo npm install --global yo 然后查看软件版本 yo --version && bower --v ...

  7. org.hibernate.TransientObjectException

    使用JPA注解@ManyToMany做一个多对多的用例. 为了避免在删除主表数据时同时级联删除从表数据,JPA官方文档建议在主表的从表字段使用级联注解:CascadeType.PERSIST,Casc ...

  8. Git的搭建和使用技巧完整精华版

    [Git使用技巧] 1.把一个已经存在于版本库中的文件加入忽略提交文件(.gitignore)中,需要如下代码: git rm --cached [文件路径] 例如: git rm --cached  ...

  9. HDU 2222:Keywords Search(AC自动机模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=2222 KMP是单模式串匹配的算法,而AC自动机是用于多模式串匹配的算法.主要由Trie和KMP的思想构成. 题意 ...

  10. ecstore2.0数据库词典

    数据库词典= 数据库tables列表 =|| Name | Comment ||| sdb_aftersales_return_product | 售后申请 || sdb_b2c_brand | 商品 ...