JSP 数据交互 使用application记录访问人数+cookie的使用
来源:互联网 发布:用单片机测量电能 编辑:程序博客网 时间:2024/05/16 07:10
1cookie:实现session基础
2.cookie分类:会话级别:没有设置期限(setMaxAge())
硬盘级别:有设置期限(setMaxAge())
cookie不是内置对象
cookie形成在服务器端,保存在客户端
page>request>response>application 都是内置对象一共9个
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>My JSP 'myapp.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--> </head> <body> <% Integer count=(Integer)application.getAttribute("count"); if(count!=null){ count++; }else{ count=1; } application.setAttribute("count", count); %> 一共有<%=count %>位访问 </body></html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>My JSP 'login.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--> </head> <body> <% Cookie[] cookies=request.getCookies(); if(cookies!=null){ for(int i=0;i<cookies.length;i++){ if(cookies[i].getName().equals("cookieName")){ response.sendRedirect(path+"/sccece.jsp"); } } } %> <%=path %> <form name="form1" method="post" action="do.jsp"> 用户名:<input type="text" name="username"> 密码:<input type="password" name="pwd"> <input type="submit" value="登录"> </form> </body></html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>My JSP 'do.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--> </head> <body> <%="=====================do==============" %> <br> <% request.setCharacterEncoding("utf-8"); String name=request.getParameter("username"); String pwd=request.getParameter("pwd"); if(name.equals("1")&&pwd.equals("1")){//request.setAttribute("name", name);//request.setAttribute("pwd", pwd);session.setAttribute("name", name);//创建cookie Cookie cookie=new Cookie("cookieName",name);//设置cookie的过期时间 cookie.setMaxAge(60*5); //将cookie响应给客户端 response.addCookie(cookie); request.getRequestDispatcher("/sccece.jsp").forward(request, response); }else{ //转发request.setAttribute("name", name); request.getRequestDispatcher("login.jsp").forward(request, response); //重定向 response.sendRedirect(path+"login.jsp"); } %> </body></html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>My JSP 'sccece.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--> </head> <body> <%="=======================sccece===========" %> </body></html>
限定时间 登录一次可以保存的时间是5分钟 如果在5分钟内你登录了 直接跳转到sccece页面 ,如果你5分钟后登录 你就得重新登录才可以
不懂私信我
0 0
- JSP 数据交互 使用application记录访问人数+cookie的使用
- jsp application对象使用 统计访问人数
- jsp application对象使用 统计访问人数
- cookie记录访问人数
- JSP数据交互(application、cookie)
- JSP数据交互:application和cookie
- Jsp使用HttpSessionBindingListener实现在线人数记录
- 使用Cookie记录访问数
- application简单实现记录系统访问人数
- jsp的cookie使用
- JSP Cookie的使用
- JSP Cookie的使用
- JSP使用网站访问人数统计功能,方法与技巧
- 记录上一次访问时间 Cookie的使用
- 关于jsp内置对象Session和Cookie使用的肤浅理解,如何使用Session来统计网站在线人数
- 关于jsp内置对象Session和Cookie使用的肤浅理解,如何使用Session来统计网站在线人数
- 关于jsp内置对象Session和Cookie使用的肤浅理解,如何使用Session来统计网站在线人数
- 使用application记录页面访问次数
- C# excel数据批量导进后添加进数据库中
- 堆栈的定义与操作(链式存储)
- java中的%运算符是取余还是取模?
- Application原理与应用
- jsp数据交互(二)
- JSP 数据交互 使用application记录访问人数+cookie的使用
- 多线程(4)- Lock和Condition
- 【转】隐函数绘制并提取数据
- Jvm 参数配置
- arm处理器
- L1-010. 比较大小
- 网页中插入视频方式
- Android 捕获系统log
- spring-mvc多视图解析配置实例 ContentNegotiatingViewResolver