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

 

posted on 2013-11-28 14:24  邵邵  阅读(150)  评论(0编辑  收藏  举报

淘宝美工兼职招聘