Java J2ME JSP J2EE Servlet Android

Using Session in JSP

Session is very important in we programming. There are many use of session in web programming. Java servlet/ Jsp provide easy way to work with session.

See the following code...
<%
Vector users = new Vector();
users.add("ABC");
users.add("BCD");
users.add("CDE");
session.setAttribute("users", users);
%>

This will set the Vector object users to session with name users.

To get values from session we can do the following..
<%
Vector users = (Vector)getAttribute("users");
for(int i=0;i<users.size();i++)
out.print((String)users.get(i)+"<br >");
%>

In this way we can handle session in JSP/servlet.

For any query just add comment..