?
Solved

why new URLConnection in java application can't keep session

Posted on 2003-02-20
8
Medium Priority
?
1,139 Views
Last Modified: 2008-02-01
Hi,
My java-application client work this way:
first request for book list, then request for infomation of a special book by index. By I find the second request can't store the cookie from first session.
Here is my relative code:
URL url = new URL(URLAdresse);
URLConnection urlConnection = url.Connection();
if (!cookie.equals("")){
urlConnection.setRequestProperty("cookie", cookie);
}
urlConnection.connect();

kindly tell me why, thks!

0
Comment
Question by:cyclops-wolf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
8 Comments
 
LVL 2

Expert Comment

by:sfotex
ID: 7997543

urlConnection.setRequestProperty("cookie", cookie);

Should setRequestProperty("cookie" be capitalized? "Cookie"
0
 
LVL 2

Expert Comment

by:sfotex
ID: 7997777

urlConnection.setRequestProperty("cookie", cookie);

Should setRequestProperty("cookie" be capitalized? "Cookie"
0
 

Author Comment

by:cyclops-wolf
ID: 8005371
 I have try "cookie" A"Cookie" and "Cookies", but result is the same.
  It is a demo of strust, download from http://javaboutique.internet.com/tutorials/Swing2/swing2.zip.
  Wellcome to use it and share the pain :)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:cyclops-wolf
ID: 8005379
 I have try "cookie" A"Cookie" and "Cookies", but result is the same.
  It is a demo of strust, download from http://javaboutique.internet.com/tutorials/Swing2/swing2.zip.
  Wellcome to use it and share the pain :)
0
 

Author Comment

by:cyclops-wolf
ID: 8005601
Now I Got it!

To resolve this problem, trim all of the info except "SESSIONID=XXXXXXX". Code should write this way:

URL url = new URL(URLAdresse);
URLConnection urlConnection = url.Connection();
if (!cookie.equals("")){
int pos = cookie.indexOf(';');
String session = cookie.substring(0, pos).trim();
urlConnection.setRequestProperty("cookie",session);
}
urlConnection.connect();

0
 

Accepted Solution

by:
cyclops-wolf earned 0 total points
ID: 8005853

To resolve this problem, trim all of the info except "SESSIONID=XXXXXXX". Code should write this way:

HttpURLConnection huc1 = (HttpURLConnection)conn;
huc1.setRequestMethod("GET");
huc1.setDoOutput(true);
huc1.setDoInput(true);
huc1.setUseCaches(false);
huc1.setDefaultUseCaches(false);
huc1.setFollowRedirects(false);
huc1.setInstanceFollowRedirects(false);
if (!cookie.equals("")){
 int pos = cookie.indexOf(';');
 String session = cookie.substring(0, pos).trim();
 huc1.setRequestProperty("cookie",session);
}
0
 

Expert Comment

by:CleanupPing
ID: 9059181
cyclops-wolf:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month12 days, 21 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question