Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Passing session ID over HttpURLConnection

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Passing session ID over HttpURLConnection

    Hi,

    I have a jsp page and a class. I am creating a new object from the class in the jsp and in the class I have HttpURLConnection, the url given is authorization required it mean it checks for the session.

    What I want to do is I want to pass the session in jsp to HttpURLConnection.

    Here is my jsp:

    ExportToPDF pdf = new ExportToPDF();
    pdf.setUrlString("http://www.javaprogrammingforums.com");
    pdf.createPDF(request, response, session);

    and here is my method in my class:

    public void createPDF(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws IOException, ParserConfigurationException, 
    			SAXException, DocumentException {
     
    		String sessionId = session.getId();
    		URL url	= new URL(this.getUrlString());
     
    		HttpURLConnection urlConn = null;
    		urlConn = (HttpURLConnection) url.openConnection();
     
    		urlConn.setRequestMethod("POST");
                    HttpURLConnection.setFollowRedirects(true);
                    urlConn.setDoOutput(true);
                    urlConn.setDoInput(true);
                    urlConn.setUseCaches(false);
                    urlConn.setAllowUserInteraction(false);
                    urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                    urlConn.setRequestProperty("Content-Language", "en-US");
                    urlConn.setRequestProperty("Cookie", sessionId);
     
    		InputStream byteStream 	= urlConn.getInputStream();
     
    		OutputStream os = response.getOutputStream();


    Can you help me what am I missing here ?
    Thank you.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Passing session ID over HttpURLConnection

    This thread has been cross posted here:

    http://www.java-forums.org/new-java/45522-passing-session-id-over-httpurlconnection.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting


Similar Threads

  1. HttpURLConnection null pointer exception
    By chopficaro in forum Java Theory & Questions
    Replies: 0
    Last Post: May 10th, 2010, 10:19 AM
  2. java.net.HttpURLConnection:large file to upload
    By tommy_725 in forum Java Networking
    Replies: 1
    Last Post: October 28th, 2009, 11:53 AM
  3. Java session problem
    By Padmaja in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: August 5th, 2009, 09:06 PM
  4. Session Timeout in LDAP
    By retail_deepa in forum Java Servlet
    Replies: 0
    Last Post: August 4th, 2009, 03:26 AM
  5. How can i put session in Javascript?
    By rajani in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: July 8th, 2009, 12:46 PM