Results 1 to 8 of 8
- 06-20-2011, 12:25 PM #1
Member
- Join Date
- Jun 2011
- Posts
- 6
- Rep Power
- 0
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:
and here is my method in my class:Java Code:ExportToPDF pdf = new ExportToPDF(); pdf.setUrlString("http://www.javaprogrammingforums.com"); pdf.createPDF(request, response, session);
Java Code: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.
- 06-20-2011, 04:19 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,605
- Rep Power
- 5
cross posted at Passing session ID over HttpURLConnection
- 06-20-2011, 04:50 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,455
- Rep Power
- 16
I might be being a bit confused here, but I presume that website you are trying to connect to is not the current website (server) you are running this code from?
If so then why are you sending the session id for your current session on your server?
- 06-20-2011, 08:22 PM #4
Member
- Join Date
- Jun 2011
- Posts
- 6
- Rep Power
- 0
Hi,
Thank you for your response.
Yes the URL I am trying connect is in the same server. I will try to explain what I am trying to do.
The page which I want to connect is authorized with session value. I want to connect that page to create a PDF version of that page.
So how can I achieve this ?
- 06-21-2011, 09:24 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,455
- Rep Power
- 16
So you've got an html to pdf converter, and you want to turn a page on your website into a PDF.
OK.
That Cookie parameter I believe should have "<parameter_name>="+sessionId.
Now, I don't know what the parameter name for the session is is, so you might need to look in the cookie produced by your site and see.
- 06-21-2011, 09:46 AM #6
Member
- Join Date
- Jun 2011
- Posts
- 6
- Rep Power
- 0
Hi,
So the way I am on is correct isnt it ?
There is only JSESSIONID which I need.
- 06-21-2011, 09:53 AM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,455
- Rep Power
- 16
I think so.
This should set the cookie:
Try it.Java Code:urlConn.setRequestProperty("Cookie", <correct string here>);
- 06-21-2011, 02:02 PM #8
Member
- Join Date
- Jun 2011
- Posts
- 6
- Rep Power
- 0
Similar Threads
-
C# HttpURLConnection to java
By jmorr212 in forum NetworkingReplies: 0Last Post: 02-24-2011, 10:29 AM -
passing a db connection across jsps throughout a session
By Tirka in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 07-18-2009, 01:32 PM -
How do you get and set cookies with HttpURLConnection
By J-Live in forum NetworkingReplies: 21Last Post: 05-21-2009, 01:53 PM -
How do I create session for a user when S/he login and expire the session.
By dpk_vash in forum Web FrameworksReplies: 2Last Post: 12-23-2008, 06:35 PM -
how to POST data to server using HttpURLConnection ??
By dhana in forum NetworkingReplies: 4Last Post: 10-15-2008, 01:59 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks