日期:2014-05-18  浏览次数:20825 次

请问这个JSP的SESSION为什么是NULL
在session_login.html里面提交name
<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 ">
<title> 无标题文档 </title>
</head>

<body>
<form   name= "form1 "   method= "post "   action= "check.jsp ">
    <label> name
    <input   type= "text "   name= "name ">
    </label>
<br>
<input   name= "ok "   type= "submit "   value= "提交 ">
</form>
</body>
</html>
在check.jsp里面写入session
<%@   page   contentType= "text/html;   charset=gb2312 "   language= "java "   import= "java.sql.* "   errorPage= " "%>
<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 ">
<title> 无标题文档 </title>
</head>

<body>
<%
String   name   =   request.getParameter( "name ");
session.setAttribute( "name ",name);
response.sendRedirect( "success.jsp ");
%>
</body>
</html>
在success.jsp页面里面读出session
<%@   page   contentType= "text/html;   charset=gb2312 "   language= "java "   import= "java.sql.* "   errorPage= " "   %>
<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 ">
<title> 无标题文档 </title>
</head>

<body>
<%=request.getAttribute( "name ")%>
</body>
</html>
现在这三个页面均可以执行   在name表单里输入内容后   在最后的   =request.getAttribute( "name ")出来的值是null
请问是不是有什么不对的地方

------解决方案--------------------
应该是session.getAttribute( "name ")吧,你试一下
------解决方案--------------------
应该是: <%=session.getAttribute( "name ")%>