Win a copy of Functional Reactive Programming this week in the Other Languages forum!
    Bookmark Topic Watch Topic
  • New Topic

Problem with session

 
Frank Tollenaar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 6920
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.
 
Frank Tollenaar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Report post to moderator
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 ]
 
Alex Qiu
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Report post to moderator
Maybe try to set the cookie name with
"JSESSIONID" instead .
See does it works , I just read it from specs .
XD
 
    Bookmark Topic Watch Topic
  • New Topic