<html>
<head>
<title>Welcome</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<%
session.setAttribute("username","baby");
session.setAttribute("password","baby");
%>
<body>
ID:<%=session.getId()%>
<p>Your username is:<%=session.getAttribute("username")%>
</p>
<p>Your password is:<%=session.getAttribute("password")%>
</p>
</body>
</html>
<head>
<title>Welcome</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<%
session.setAttribute("username","baby");
session.setAttribute("password","baby");
%>
<body>
ID:<%=session.getId()%>
<p>Your username is:<%=session.getAttribute("username")%>
</p>
<p>Your password is:<%=session.getAttribute("password")%>
</p>
</body>
</html>
-->
<% out.println(session.getAttribute("username").toString());%>
or
<%=session.getAttribute("username").toString()%>
可是我原来是想在一个servlet里面设置session的值:
HttpSession login_session = request.getSession(true);
login_session.setAttribute("username", var0);
login_session.setAttribute("password", var1);
然后重定向到这个jsp页面:
response.sendRedirect("http://10.160.65.240:7001/ss.jsp");
然后再在这个ss.jsp里面把session里的东西取出来:
<%=session.getAttribute("username")%>
<%=session.getAttribute("password")%>
为什么取出来的都是null呢?是不是重定向后就不是一个session了?
然后在jsp里调用。
比如sendredirect("/myDirectory/mypage.jsp");
重新一下http://...相当于另外一个会话,session当然没了!