| Java FAQ | ||
| JSP FAQ | ||
| Servlet FAQ | ||
XyzWs JSP FAQ:
How to display all the session variables in an HTML page?
Printer-friendly version |
Mail this to a friend
|
Advertisement
|
How to display all the session variables in an HTML page?
The session implicit object is an instance of There's no way you can do it directly from plain HTML since HTML is static and the session object really "lives" in the dynamic environment of the web container. The following example JSP shows you how to generate HTML that shows the objects in the session attribute collection.
<%@ page language="java" import="java.util.*" %>
<html>
<body>
Session attributes:
<%
session.setAttribute("test.name", "Test Attribute List");
session.setAttribute("test.float", new Float(5.0));
session.setAttribute("test.int", new Integer(10));
session.setAttribute("test.Object", new StringBuffer("StringBuffer"));
session.setAttribute("test.boolean", new Boolean(true));
session.setAttribute("test.double", new Double(343.1));
for (Enumeration e = session.getAttributeNames(); e.hasMoreElements(); ) {
String attribName = (String) e.nextElement();
Object attribValue = session.getAttribute(attribName);
%>
<BR><%= attribName %> - <%= attribValue %>
<%
}
%>
</body>
</html>
|