Solved

Can I access session variables after using a httpsURLConnection call?

Posted on 2004-04-14
4
548 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In 2017, ransomware will become so virulent and widespread that if you aren’t a victim yourself, you will know someone who is.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

864 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now