zoukankan      html  css  js  c++  java
  • cookie

    <%@ 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 'a.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演示:
         cookie路径:不是打开每个浏览器页面,都会发送所有浏览器缓存的cookie,而是要看访问URL是否包含cookie保存路径;cookie保存路径是tomcat服务器保存的,默认为/day_11_2/Cookie;
         --%>
         <font color="red">保存Cookie</font>
      <%
      Cookie cookie = new Cookie("name","value");
      //设置cookie存活时间  >0 存活时间以秒计算  <0 表示存活时间为浏览器开启时间,一旦浏览器关闭cookie就灭亡   ;=0 cookie立即死亡
      cookie.setMaxAge(60*60);
      
      //保存cookie
      response.addCookie(cookie);
      %>
      <%-- 
      <% 
      //演示多个项目共享cookie,首先创建cookie对象设置cookie域,匹配2级域名例如:www.baidu.com  zhidao.baidu.com  设置cookie路径为“/”
      Cookie cookie1 = new Cookie("name","value");
      cookie1.setDomain(".baidu.com");
      cookie1.setPath("/");
      %>
      --%>
      </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 'b.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>
      <font color="red">获取Cookie</font><hr/>
        <%
        //获取cookie注意返回的是数组
        Cookie[]cookies = request.getCookies();
        //判断cookie数组是否为null,如果不为null就遍历;
        if(cookies!=null){
            for(Cookie cookie : cookies){                            //获取Cookie路径
                out.print(cookie.getName()+":"+cookie.getValue()+":"+cookie.getPath()+"<br/>");
            }
        }
        %>
      </body>
    </html>
  • 相关阅读:
    An internal error occurred during: "Launching MVC on Tomcat 6.x". java.lang.NullPointerException
    bat批处理文件夹内文件名的提取
    人脸识别-常用的人脸数据库
    WPF RichTextBox 做内容展示框 滚动条控制判定是否阅读完成
    WPF+通过配置文件生成菜单(Menu)+源码
    程序员也可以浪漫----倾情奉献一份你值得拥有的浪漫网站源码(情人节快来了~)
    这世界唯一的你:最美程序媛走红网络
    20分钟读懂程序集
    简介4种同步方法的实现
    共享文件夹:The user has not been granted the requested logon type at this computer
  • 原文地址:https://www.cnblogs.com/wangyinxu/p/7402297.html
Copyright © 2011-2022 走看看