Session in JSP Example to use Sessing Object in JSP
You can use Session object in jsp with object "session"
Example Code for JSP session
This Example Show you for
- How to set object to session
- How to get value from session by key
- How to get Session ID
- How to collect attribute name from session
- How to destroy session
<%
//You can put object to session with key and value
session.setAttribute("key","Value Object");
session.setAttribute("key1","Value1");
// Get Data from Session by Key
String data=(String)session.getAttribute("key1");
// Get Session id from session object
String sessionID=session.getId();
//Load all attribute name from session to Enumeration
Enumeration em=session.getAttributeNames();
while(em.hasMoreElements()){
out.println(em.nextElement());
}
//Destroy session
session.invalidate();
%>