Aboutsession

HelloI need session for login.I want to put one parameterin session variable when user is login.Do you have some example with session or some explanation. I don't know a lot about session.Thank you
[255 byte] By [larakroft] at [2007-9-27 14:03:45]
# 1

Session ,You can assume to be, a cookie of sorts on the server. So when you login, just type the following in your code

<% session.setAttribute("someString",yourParameter); %>

The above statement pushes your object to the session or rather associates a reference of your object to the session.

The general form of the setAttribute is "session.setAttribute(String,Object).

Try this.

pradeepsridharan at 2007-7-5 21:53:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Thank you!!! I have still one question if it is not a problem.How can I check what is in session. When I take getAttribute can I use out.println or somethig else .I read that i have to cast what i catch
larakroft at 2007-7-5 21:53:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Thank you a lot for your time!!! I have still one question if it is not a problem.How can I check what is in session. When I use getAttribute do I need tocast. I read about it.When I catch what is in session with getAttribute how cab I use it later. J
larakroft at 2007-7-5 21:53:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
you can use <%session.setAttribute("User_name",username)%>user logout jsp page<%session.removeAttribute("User_name")%>
tissyshi at 2007-7-5 21:53:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Ya lara,

You can use a out.println after getting a reference to the object in the session. suppose, you have associated your login-id with the session using session.setAttribute("loginId",loginId);

Then in the following jsps or servlets you can use the following statement to get a reference to loginId

String loginId = (String)session.getAttribute("loginId");

then you can use out.println(loginId) to print the loginId or have an appropriate use for it according to your necessity.

pradeepsridharan at 2007-7-5 21:53:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...