<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>

解决方案 »

  1.   

    <%session.getAttribute("username").toString();%>
    -->
    <% out.println(session.getAttribute("username").toString());%>
    or
    <%=session.getAttribute("username").toString()%>
      

  2.   

    哦,这样可以了。
    可是我原来是想在一个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了?
      

  3.   

    楼上的,login_session没定义,在servlet和jsp不一样的
      

  4.   

    应该先在servlet里把session定义一下。
    然后在jsp里调用。
      

  5.   

    冲定向的时候去掉http://...,可以直接根据目录写重定向文件
    比如sendredirect("/myDirectory/mypage.jsp");
    重新一下http://...相当于另外一个会话,session当然没了!
      

  6.   

    我知道怎么回事了,谢谢大家!无论在sendredirect后加不加http都可以取到session的值的,我试验了一下,只要你重定向的页面是和设定session的servlet在同一个webApplication(即同一个.war中),就可以取到值,不在同一个webApplication中就不行。^o^,难道我要把整个站点都打到同一个.war中么?希望感兴趣的朋友和我讨论这个问题。我的Email是:[email protected]总之不管如何,谢谢各位。