This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Problem with session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Reply locked New topic
Author

Problem with session

Frank Tollenaar
Greenhorn

Joined: Dec 18, 2006
Posts: 18
Hi,
I'm not sure if I am in the good groupe because this question is tied with many aspect of java.
I've done many JSP which store some values in session. When I test it with a browser like IE5, the session work the values are transfer to the other page until I close the browser. This works very fine.
BUT when I use a Java Application the values don't store in the session. Here how it works normally.
In my application I open an login dialog who call the corresponding jsp lets call it login.jsp. When he found the corresponding user in the database it put the value in the session (UserID).
After that I want for example to change my password. So I open my dialog box in my application I write my new password and call the corresponding jsp (change.jsp). But he never find any UserID because it's value is null now. It didn't keep the session.
I think I've know what the problem is but can't solve it.
Here I call two jsp, each time I made an URLConnection.openConnection().
I think when I call this, a new session is opening and this is causing me the problem.
Am i right? And if yes how can I solve this problem?
Thanks in advance for the answer
Frank

Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
My guess is that your application is not storing the cookies sent by the JSPs.
To implement sessions in an application pretending to be a browser, you need to catch the "cookie" headers sent by the server, store them and time them out according to the rules for cookie handling, and send them back to the server the next time you access another servlet or JSP.
If you can't build cookie handling into your client application, you will need to use URL-rewriting in your servlets/JSPs, but this is more complicated and error-prone.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Frank Tollenaar
Greenhorn

Joined: Dec 18, 2006
Posts: 18
Thanks this help me to advance a little more. It's effectively a problem with cookie.
I found that the servlet send me 4 cookies. I put them all on a string, separated by ; (not sure if it's the good separation, can someone confirm me that?). When I request another jsp I'm doing this :
URL url = new URL(URLAdresse);
URLConnection urlConnection = url.openConnection();
if (!cookie.equals("")){
urlConnection.setRequestProperty("Set-Cookie", cookie);
}
urlConnection.connect();
but this is not working, anybody have an idea of what is happening?

chen juxing
Greenhorn

Joined: Feb 19, 2003
Posts: 4
the code should write this way:
URL url = new URL(URLAdresse);
URLConnection urlConnection = url.openConnection();
if (!cookie.equals("")){
urlConnection.setRequestProperty("cookie", cookie);
}
urlConnection.connect();
Note: I get it from internet-articles, but it's seens that still can't work, I don't know why. if you do, tell me pls!
good luck-)
[ February 20, 2003: Message edited by: chen juxing ]

can't stop learning new
Alex Qiu
Greenhorn

Joined: Jul 19, 2002
Posts: 24
Maybe try to set the cookie name with
"JSESSIONID" instead .
See does it works , I just read it from specs .
XD


Nothing is impossible to a willing heart .<br />----------------------------------<br />SCJP SCJD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with session
 
Similar Threads
with out authentication it is forwading to another page
tomcat session handling
Session Management
going back/refreshing page
session collusion problem