session中传值为null的简单问题!
我有两个jsp,为jsp1和jsp2,具体代码很简单,我只想测试一下session即可。
jsp1:
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>
jsp1
</title>
</head>
<body bgcolor="#ffffff">
<%
String IP;
session.setAttribute("IP","202.120.121.136");
out.println(session.getAttribute("IP"));
out.println(session.isNew());
%>
<form method=post action="jsp2.jsp">
<input type=hidden name="food" value="ddd">
<p>
<input type=submit value="next">
</form>
</body>
</html>
jsp2:
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>
jsp2
</title>
</head>
<body bgcolor="#ffffff">
<%
String food=request.getParameter("food");
String name=(String)session.getAttribute("IP");
//out.println(session.getAttribute("IP"));
out.println(name);
out.println(session.isNew());
%>
<%=food%>
</body>
</html>
错误提示为:out.println(name);输出的是null