Sub : How to manage session ?

Hi Java Gurus,

Can any body tell me how to manage session in java.

I have two url sayhttp://www.xyz/userlogin.php,http://www.xyz/sendsms.php

1st url gives the login form and second one coes after succesfull login.

Now I am not using any web browser. I have to surf these pages through java code using java api ( HttpURLConnection, HttpSession, URL etc...).

I am able to access login form, but after login when I connect second url, it gives session expired message in the html stream.

This is because I am not managing session. So can any body have any idea or pointer. How I can manage sesssion and access second page after succesfull login.

I will appreciate your help.

Thanks and regards -

Vikas Kumar Sahu.

[772 byte] By [vikassahua] at [2007-10-3 4:30:30]
# 1

Where did the HttpSession class come from? If it's from javax.servlet.http then it's not appropriate for a client program. What you need to do is handle the cookies that the server is going to send you, one of these will include the session id.

To see what it sends, login using Firefox and then go to tools>options>privacy>cookies>view cookies.

pkwoostera at 2007-7-14 22:33:44 > top of Java-index,Java Essentials,Java Programming...
# 2

What I do in some of our test-clients is that I call the login and get all the cookies from the header and add them to the next request.

More or less what pkwooster suggested.

Also, I suggest that you take a look at http://jakarta.apache.org/commons/httpclient/

and the Example code http://svn.apache.org/viewvc/jakarta/commons/proper/httpclient/trunk/src/examples/CookieDemoApp.java?view=markup

Message was edited by:

Lajm

Lajma at 2007-7-14 22:33:44 > top of Java-index,Java Essentials,Java Programming...
# 3
Thanks friends.
vikassahua at 2007-7-14 22:33:44 > top of Java-index,Java Essentials,Java Programming...