Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2008

Tip: Looking for answers? Try searching our database.

Maintaining sessions with URL

Thread view: 
Dev - 14 Feb 2008 16:13 GMT
Greetings,

It seems to be puzzle for me but I am sure such kind of requests could
have been handled and addressed. This is my requirement:

Manual Steps currently followed:
1. Supply the ISBN number and click OK
2. the web page returns list of books (if the ISBN number is partly
entered)
3. click on the desired list
4. the web page returns the details of the book like book name, etc

We have a requirement to validate around 50000 ISBN and doing it
manually will be laborious. Hence I thought it could be automated.

This was my approach:
1. Create URL String with Post data
2. open the URLConnection
3. read the returned web page and get the total count of books
returned
4. create another URL string and open the url connection
5. read the web page and parse the details

Until Point 3, I was able to accomplish. However, when another
connection was established, the returned page was session expired.

I should bascially use the same URL object to repost or redirect to
the server with my second URL. Not sure how I could accomplish
Please help!

The code snippet which is abridged version.

final String URL1 = "http://www.google.com?isbn=123
&startrow=1&endrows=10"

final String URL2= "http://www.google.com?whichrow=1"

...
...
URL url = new URL (url1);
URLConnection urlconn =  url.openConnection ();

urlconn.setDoOutput(true);
urlconn.setUseCaches(false);
urlconn.setRequestProperty("Content-Type", "application/x-www-form-
urlencoded");

readContents ();

url = new URL (url2);
urlconn = url.openConnection ();
...
parsehtml()
Daniel Pitts - 14 Feb 2008 19:31 GMT
> Greetings,
>
[quoted text clipped - 27 lines]
>
> The code snippet which is abridged version.

[snip]
Look into using HttpClient from apache commons. It has much better
session handling.

Signature

Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

Arne Vajhøj - 14 Feb 2008 23:00 GMT
> It seems to be puzzle for me but I am sure such kind of requests could
> have been handled and addressed. This is my requirement:
[quoted text clipped - 23 lines]
> the server with my second URL. Not sure how I could accomplish
> Please help!

> URL url = new URL (url1);
> URLConnection urlconn =  url.openConnection ();

URLConnection does not maintain sessions.

Switch to Jakarta HttpClient:
  http://hc.apache.org/httpclient-3.x/index.html
it understands sessions.

Arne
Dev - 15 Feb 2008 21:35 GMT
Perfect!
It works as required.

Thank you~
-Dev


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.