有时在jsp页面的调试中,我们要取出session中的所有值,那该如何来实现:
java.util.*;
//获取session HttpSession session = request.getSession(); //获取session中所有的键值 Enumeration enumeration = session.getAttributeNames(); //遍历enumeration中的 while (enumeration.hasMoreElements()){ //获取session键值 String name = e.nextElement().toString(); //根据键值取session中的值 Object value = request.getAttribute(name); //打印结果 out.println("<B>" + name + "</B> = " + value + "<br>/n"); }
----------------------------------------
//获取session HttpSession session = request.getSession();
//获取键名 String[] names = session.getValueNames();
//循环遍历 for (int i = 0; i < names.length; i++) {
//打印 out.println(names[i] + “: ” + session.getValue(names[i]) + “<BR>”);
}