Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 12th, 2003, 10:45 AM
AlliosIII AlliosIII is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 5 AlliosIII User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Problem with URLconnection and session parameters

Hi all,
I'm triing to make a test program that will test all my jsp pages, for that, i have a servlet that initiate the session parameters (for loggin authorisation) and i whant that servlet to right the source code of the jsp files in a .txt.
The problem is that the session is reset when i call the jsp to write it down.
Here's some part of my code:

//here i call the session and set the parameters
HttpSession session=request.getSession(true);
session.setAttribute("user_name","auser");

//here i just call the jsp file and write it down in result.txt
URL urltt = new URL("http://www.myserveur.com/myfile.jsp");
HttpURLConnection connection = (HttpURLConnection) urltt.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setAllowUserInteraction(true);
connection.connect();
InputStream stream = connection.getInputStream();
BufferedInputStream in = new BufferedInputStream(stream);
FileOutputStream file = new FileOutputStream("result.txt");
BufferedOutputStream outBF = new BufferedOutputStream(file);

int i; while ((i = in.read()) != -1){
outBF.write(i);
}


can you tel me what's missing???


(this is on a Linux serveur on tomcat)

Last edited by AlliosIII : August 12th, 2003 at 11:08 AM.

Reply With Quote
  #2  
Old August 12th, 2003, 01:57 PM
Nemi Nemi is offline
Clueless llama
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353 Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 12 h 35 m 19 sec
Reputation Power: 111
If you are connecting to a jsp from a servlet and want your session to be available in the jsp you have to pass the session cookie along. Iterate through all your cookies and find the session cookie and add it to the connection object. Make sense?

Reply With Quote
  #3  
Old August 13th, 2003, 04:05 AM
AlliosIII AlliosIII is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 5 AlliosIII User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Can it be donne without cookies?

It does make sense but we don't use cookies to save the session parameters. If i do that now it will be more than 150 jsp pages that will need to be changed only for my test routine since we whant to keep the authentification methode has it is right know.

Plus, what i really whant is to be able to add the session object to the HttpURLConnection object. (or to find another connection type that takes the session along)
You say to add the cookie to the connection, do you have any example on how to do it for me to try to adapt it to the HttpSession object?


And thanx for answering

Reply With Quote
  #4  
Old August 13th, 2003, 09:00 AM
AlliosIII AlliosIII is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 5 AlliosIII User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Talking

Well i found out a solution to my problem, insted of writting the jsp page from the servlet i include the jsp in the servlet and i write down the servlet from my program

thx for you time

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Problem with URLconnection and session parameters


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT