Solved

Can I access session variables after using a httpsURLConnection call?

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Let’s face it: one of the reasons your organization chose a SaaS solution (whether Microsoft Dynamics 365, Netsuite or SAP) is that it is subscription-based. The upkeep is done. Or so you think.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

688 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