Solved

Can I access session variables after using a httpsURLConnection call?

Posted on 2004-04-14
4
553 Views
Last Modified: 2012-05-04
I am a first time poster and new to web programmer so forgive my ignorance.  

I have a secure web site where a user logs in with a username and password.  This is saved in a session variable named credentials.  As the user process information, he wants to be able to save the information to the server in html file to be able to access that data at a later date.  I have written a servlet that will do this (right now it is only writting to standard out).

The problem is that the first thing the jsp page does is check for the credentials session variable to make sure the user is logged into the site.  I have lost this session variable using the HttpsURLConnection.  Is there any way to pass this in?  Or is there better way to do this?

      HttpsURLConnection.setDefaultHostnameVerifier( hnv );
            String urlString = request.getParameter("urlString");
            URL formUrl = new URL(urlString);
            HttpsURLConnection connection = (HttpsURLConnection)formUrl.openConnection();
            System.out.println("OPEN CONNECTION SUCCESSFUL: "+formUrl);        
            connection.connect();
            System.out.println("CONNECTED: "+formUrl);        

            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));

            String inputLine;
            System.out.println("BEFORE WHILE");        

            while ((inputLine = in.readLine()) != null)
            {
                  System.out.println(inputLine);                        
            }

            in.close();
0
Comment
Question by:mtiGirl
[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
  • 3
4 Comments
 
LVL 3

Expert Comment

by:int_20h
ID: 10828805
you need to set all the cookies that you got in the servlet and pass it to the HttpsUrlConnection.  The session that you have in the server is store in a Session ID Cookie; so sending all cookies that you have at that point will do the trick!
0
 
LVL 3

Expert Comment

by:int_20h
ID: 10829078
Sorry, No Servlet... JSP! :)
0
 

Author Comment

by:mtiGirl
ID: 10829360
I don't have any experience using cookies, could you give me just a little direction here.  Also, are you saying that I should write this as a jsp page instead of a servlet?

Thanks for you input!
0
 
LVL 3

Accepted Solution

by:
int_20h earned 250 total points
ID: 10834634
Oh... I thought you're using JSP for this...If you are using servlet, you can do servlet chaining if you're trying to send it to a servlet within the same container:
http://hudsonfog.com/dev-doc/ServletChaining.html?action=template
If you want to send the cookies to another container, you need to use setRequestProperty.  Here is a site that can help:
http://martin.nobilitas.com/java/cookies.html
But if I were you, I would use a HTTP library like:
http://www.innovation.ch/java/HTTPClient/
http://jakarta.apache.org/commons/httpclient/
Those libraries will make handling HTTP and cookies a lot simplier...
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

Suggested Solutions

Title # Comments Views Activity
TreeSet comparator example 7 109
Spring MVC - sending raw charset to backend 3 269
HTTPSessionBindingListernter not configured in deployment descriptor 2 75
print map entry 34 79
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
Invest in your employees with these five simple steps to improve employee engagement and retention.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 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