我都想问这个问题啊,如何可以获得session里的所有变量的名和对应的值

解决方案 »

  1.   

    try:<%@ page contentType="text/html;charset=gb2312"%>
    <%
    request.getSession().setAttribute("sesExampleA","0001");
    request.getSession().setAttribute("sesExampleB","abcd");
    request.getSession().setAttribute("sesExampleC","defg");
    %>
    <a href=next.jsp>下一页</a>next.jsp
    <%@ page contentType="text/html;charset=gb2312"%>
    <%@ page import="java.util.*" %>
    <%
    request.getSession().setAttribute("nextExample","nextValue");Enumeration e = request.getSession().getAttributeNames() ;
    String sName = "" ;
    while(e.hasMoreElements()){
    sName = e.nextElement().toString() ;
    out.print("<br>"+sName+"==="+request.getSession().getAttribute(sName));
    }
    %>
      

  2.   

    运行这几句报错。
    request.getSession().setAttribute("sesExampleA","0001");
    request.getSession().setAttribute("sesExampleB","abcd");
    request.getSession().setAttribute("sesExampleC","defg");
      

  3.   

    Andrawu(晓彬)的例子正确,是你的问题,哪里没设置好。
      

  4.   

    <%@ page contentType="text/html;charset=gb2312"%>
    <%
    session.setAttribute("sesExampleA","0001");
    session.setAttribute("sesExampleB","abcd");
    session.setAttribute("sesExampleC","defg");
    %>
    <a href=next1.jsp>下一页</a>next1.jsp<%@ page contentType="text/html;charset=gb2312"%>
    <%@ page import="java.util.*" %>
    <%
    session.setAttribute("nextExample","nextValue");Enumeration e = session.getAttributeNames() ;
    String sName = "" ;
    while(e.hasMoreElements()){
    sName = e.nextElement().toString() ;
    out.print("<br>"+sName+"==="+session.getAttribute(sName));
    }
    %>以上两个例子我都测试过!