java后台打印session内容
HttpSession session = request.getSession(); //将person对象绑定到session中 Person p = new Person("100","jack"); session.setAttribute("person",p); // 获取session中所有的键值 Enumeration<?> enumeration = session.getAttributeNames(); // 遍历enumeration while (enumeration.hasMoreElements()) { // 获取session键值 String name = enumeration.nextElement().toString(); // 根据键值取session中的值 Object value = session.getAttribute(name); // 打印结果 System.out.println(name + " : " + value); }
打印结果 person : Person [id=100, name=jack]