Httpunit help? Maintaining sessions/cookies.

J

John Laury

Hello There!

I am having problems establishing a session using httpunit. What I am
trying to do is to access one page (page1.jsp) that leaves a cookie on
my computer and access a second page (page2.jsp) that can only be
accessed if the cookie from the first page is present. If there is no
cookie available from the first page, then the second page would
redirect user to an error page indicating that a session does not
exist.

I have the following piece of code using HTTPUNIT:

..
..
..
WebConversation wc = new WebConversation();
WebRequest request = new GetMethodWebRequest(
"http://www.myhost.com/page1.jsp" );
WebResponse response = wc.getResponse( request );

WebRequest request2 = new GetMethodWebRequest(
"http://www.myhost.com/page2.jsp" );
WebResponse response2 = wc.getResponse( request2 );
String fileContents = response2.getText();
..
..
..

Unfortunately, the 'fileContents' variable contains the error page
that I am redirecting the user in case a cookie is not being
recognized. In other words, when making the second webrequest, it
doesn't seem like the cookie obtained from the first webrequest is
being used. Can anyone tell me why this might be happening?

I would greatly appreciate all responses.

Thanks,

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top