你取出的值当然是空,因为你并没有把表单的各个值取出来,默认的当然是空。你可以这样做:三个jsp页面:jsp1.jsp的代码为:
<%@ page contentType="text/html;charset=UTF-8" %>
<%@page import="java.util.*"%>
<html>
<head>
</head>
<body >
<%!String username,password,checkbox1;%>
<FORM name="form1"  method="post" action="jsp2.jsp">
<INPUT type="text" name="username">  
<INPUT type="text" name="password" />
<INPUT type="Submit" name="submit" >   
</FORM>      
</body>
</html>
jsp2.jsp的代码为:
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
</head>
<body>
<% String username=request.getParameter("username");
String password=request.getParameter("password");
%>
<%           
  session.putValue("username",username);
  session.putValue("password", password) ;
  
%>

<jsp:forward page="jsp3.jsp" />
</html>
jsp3.jsp的代码为:
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
</head>
<body>
<%=session.getValue("checkbox1")%>
<%=session.getValue("username")%>
<%=session.getValue("password") %>
</body>
</html>
试试看,此实例帮你理解session的作用和request的作用。

解决方案 »

  1.   

    我猜测,他肯定是在第一个页面的表单下,直接用session.setAttribute()方法的,那样肯定是空值。
      

  2.   

    调试一下,看看我在做jsp,不知怎么session中取出的总是null,可是已经给session用setAttribute赋过值了,赋的值是否是null还是其他?
      

  3.   

    请确定:
    <% String username=request.getParameter("username");
    String password=request.getParameter("password");
    %>
    <%           
      session.putValue("username",username);
      session.putValue("password", password) ;
    username , password 的值不为NULL.
      

  4.   

    session.putValue("username",username);
      session.putValue("password", password) ;
    会不会是putValue的问题啊,你改成setAttribute()吧。
      

  5.   

    body>
    <% String username=request.getParameter("username");
    String password=request.getParameter("password");
    %>
    <%           
      session.setAttribute("username",username);
      session.setAttribute("password", password) ;
      
    %>

    <jsp:forward page="jsp3.jsp" />
    </html>
    jsp3.jsp的代码为:
    <%@ page contentType="text/html;charset=UTF-8" %>
    <html>
    <head>
    </head>
    <body>
    <%=session.getAttribute("checkbox1")%>//这个空不空啊
    <%=session.getAttribute("username")%>
    <%=session.getAttribute("password") %>
      

  6.   

    对了,一点小错误,下面这句话应该删掉,我当时做测试用的。
    <%=session.getAttribute("checkbox1")%>//
      

  7.   

    我晕啊.....那问题可能出现在你没有先经过setAttribute()的页面,然后直接进入了getAttribute()的页面了,再一可能就是你setAttribute()一个null的对像进去了,再一可能,没有启用session.request.getSession(true);
      

  8.   

    session.setAttribute()方法和session.getAttribute()方法