why new URLConnection in java application can't keep session

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!

cyclops-wolfAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sfotexCommented:

urlConnection.setRequestProperty("cookie", cookie);

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

urlConnection.setRequestProperty("cookie", cookie);

Should setRequestProperty("cookie" be capitalized? "Cookie"
0
cyclops-wolfAuthor Commented:
 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
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

cyclops-wolfAuthor Commented:
 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
cyclops-wolfAuthor Commented:
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
cyclops-wolfAuthor Commented:

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CleanupPingCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.