Solved

Can I access session variables after using a httpsURLConnection call?

Posted on 2004-04-14
4
547 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
Comment Utility
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
Comment Utility
Sorry, No Servlet... JSP! :)
0
 

Author Comment

by:mtiGirl
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifiā€¦
In this article, I will show you HOW TO: Create your first Windows Virtual Machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, the Windows OS we will install is Windows Server 2016.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

11 Experts available now in Live!

Get 1:1 Help Now