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中
//这个方法不是很好

 

转载于:https://www.cnblogs.com/shaoshao/p/3447637.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值