session.getvalueanames()順序不對
session_page1.jsp
<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=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 'session_page1.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>
??? <h1> session內(nèi)置對象</h1>
??? <hr>
??? <%
??? ?SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
??? ?Date d=new Date(session.getCreationTime());
??? ?session.setAttribute("最喜歡的人是","最喜歡的人是");
??? ?session.setAttribute("myz", "myz");
??? ?session.setAttribute("是你的什么?", "是我的心肝兒");
??? ?session.setAttribute("是我的心肝兒", "是我的心肝兒");
??session.setAttribute("是我的甜蜜餞兒", "是我的甜蜜餞兒");
??//session.setMaxInactiveInterval(10);
???? %>
???? session創(chuàng)建時間:<%=sdf.format(d)%><br>
???? session的ID號:<%=session.getId() %><br>
???? 從session中獲取用戶名:<%=session.getAttribute("myz")%><br>
???? <a href="session_page2.jsp" target="_blank">要上天啊</a>
????
? </body>
</html>
session_page2.jsp
<%@ page language="java" import="java.util.*" contentType="text/html; charset=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 'session_page2.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>
??? session的ID號:<%=session.getId() %><br>
??? 從session中獲取用戶名:<%=session.getAttribute("myz")%><br>
??? session保存的屬性:<%
?? ?????String[] names=session.getValueNames();
?? ?????for(int i=0;i<names.length;i++){
?? ??????out.println(names[i]+" ");
?? ?????}
???? %>
? </body>
</html>
2017-03-13
同問~
2017-03-09
這個可能因為存儲的時候是已鍵值對的形式 存儲就像 Map的<key,value>key是沒有順序的
2017-03-04
同問.貌似我用getvalueanames()他先返回的是names[1],最后返回的是names[0]