How to display all the session variables in an HTML page?
The session implicit object is an instance of javax.servlet.http.HttpSession. This variable is only valid for Http protocols. The session is one of the JSP built-in variables (like request) that is available in the service body of a JSP. (What is session implicit object in JSP?).
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>
Most Recent jsp Faqs
- How to get the real requested URI from inside the error page?
- Can I define a method in a JSP page?
- What is the difference between request.getParameter() and request.getAttribute()?
- What is difference between page and pageContext in JSP pages?
- How to config a JSP file in web.xml?
- What is the difference between jsp:forward and response.sendRedirect?
- How to retrieve values from HTML form input elements in JSP?
Most Viewed jsp Faqs
- How to config a JSP file in web.xml?
- What is difference between page and pageContext in JSP pages?
- How to disable browser caching for a specific JSP?
- How to retrieve values from HTML form input elements in JSP?
- What is the difference between jsp:forward and response.sendRedirect?
- What is the difference between request.getParameter() and request.getAttribute()?
- How to get the current JSP page name?