• session的一个问题


    <%@ page language="java" import="java.util.*,javax.servlet.http.Cookie.*" pageEncoding="utf-8"%>
    <%@taglib prefix="html" uri="http://struts.apache.org/tags-html" %>
    <%
    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">
        -->
        <!-- 这里已经生成了一个sessionId 所以会有一个sessionId-->
        <%=session.getId() %><br/>  
      </head>
      
      <!-- 下面这个cookies中不会有上面刚刚生成的sessionId,所以不会显示出来,只有当jsp跳转后,才会到cookie中取的到 -->
      <%
      Cookie cookies[]=request.getCookies();
      if(cookies!=null){
          for(int i=0;i<cookies.length;i++){
                Cookie cookie=cookies[i];
                out.println(cookie.getName() + "   " +cookie.getValue());
                if(cookie.getName().equals("JSESSIONID")){
                    out.println(cookie.getValue());
                }
        } 
      }
      %>
      <body>登录</h1>
        <form action="/strutsTest1/Test1" method="get">
            u:<input type="text" name="userName"/>&nbsp; &nbsp; <html:errors name="dd"  property="userName"/> <br/> 
            p:<input type="password" name="passWord"/><br/>
            <input type="submit"/>
        </form>
      </body>
    </html>
    
    
    //这个可以处理一个浏览器登录两个用户的问题,session中
    //这个方法不是很好
  • 相关阅读:
    Asp中JSON的使用
    POJ 3243 Clever Y Extended-Baby-Step-Giant-Step
    [Java开发之路](16)学习log4j日志
    【剑指Offer学习】【面试题49:把字符串转换成整数】
    负载均衡器&amp;http正向代理
    Android应用开发经常使用知识
    java8_api_nio
    李洪强经典面试题25(选择题)
    李洪强经典面试题24
    李洪强经典面试题23
  • 原文地址:https://www.cnblogs.com/shaoshao/p/3447637.html
Copyright © 2020-2023  润新知