?
Solved

Can I access session variables after using a httpsURLConnection call?

Posted on 2004-04-14
4
Medium Priority
?
555 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 1000 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

Introducing Priority Question

Increase expert visibility of your issues by participating in Priority Question, our latest feature for Premium and Team Account holders. Adjust the priority of your question to get emergent issues in front of subject-matter experts for help when you need it most.

Question has a verified solution.

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

An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
This month, Experts Exchange’s free Course of the Month is focused on CompTIA IT Fundamentals.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

771 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