Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with session

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic