小白请问大神们一个JSP关于session的有关问题
小白请教大神们一个JSP关于session的问题
我有两个页面,第一个页面用setAttribute()设置了3个session,然后从第一个页面跳转到第二个页面,为什么用getAttributeNames()取之前的session的时候,取不到呢? 下边是代码
第一个页面:
第二个页面:
------解决思路----------------------
显示什么错误?
------解决思路----------------------
session.getAttribute("a1");
session.getAttribute("a2");
session.getAttribute("a3");
看看
我有两个页面,第一个页面用setAttribute()设置了3个session,然后从第一个页面跳转到第二个页面,为什么用getAttributeNames()取之前的session的时候,取不到呢? 下边是代码
第一个页面:
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%
session.setAttribute("a1", "aaa");
session.setAttribute("a2", "bbb");
session.setAttribute("a3", "ccc");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Insert title here</title>
</head>
<body>
<form action="Test2.jsp" method="get">
<table>
<tr>
<td><input type="submit" value="提交">
</tr>
</table>
</form>
</body>
</html>
第二个页面:
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%
java.util.Enumeration<String> e = session.getAttributeNames();
while(e.hasMoreElements()) {
String sessionName=(String)e.nextElement();
System.out.println("\nsession item name="+sessionName);
System.out.println("\nsession item value="+request.getSession().getAttribute(sessionName));
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Insert title here</title>
</head>
<body>
</body>
</html>
------解决思路----------------------
显示什么错误?
------解决思路----------------------
session.getAttribute("a1");
session.getAttribute("a2");
session.getAttribute("a3");
看看