This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to capture a respnse object

 
vishwanath nadimpally
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using the google search feature, which returns the query results in an XML format. Now I want to parse it and generate custom HTML.Only one problem though.

I am doing a response.sendRedirect() and I get the google search results. But I want to capture the results page as an XML document in order to parse it. How can it be done?

I am not very familiar with XML,so this might sound like a stupid question.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do this with Ajax (but you'll need a server-side proxy to escape the dreaded "Ajax security sandbox"). It will return the XML document which you can then parse with JavaScript DOM functions.

If you'd rather do it on the server-side, I'd suggest "hitting" the service with URL.getConnection() in your servlet and parsing the returned response. HttpUnit is also a great tool for this.

What you probably don't want to do -- simply because it's a lot more work -- is to hit the service directly from the browser and try to intercept the response using filters and response wrappers. But that is a possible way of doing it.
[ May 11, 2006: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. <shameless-plug>If you are interested in the Ajax solution and you're a patient man, the upcoming Manning book "Ajax in Practice" will have a whole chapter devoted to using open APIs (google, Yahoo!, Flickr, et al) from Ajax.</shameless-plug>
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Other solutions could be using XSLT (would not be my choice), or perhaps even a JSP page using the JSTL "x" tags.
[ May 11, 2006: Message edited by: Bear Bibeault ]
 
vishwanath nadimpally
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for suggestions.
This article http://java.sun.com/products/servlet/Filters.html says filters can be useful too.And I think its easier for me to use this than AJAX as I am a complete stranger to AJAX.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, as I mentioned in my first reply, filters are a possibility for doing this on the server side, but I think it would be a lot easier to pursue the URL connection route. But either means should work for you.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another reason to do the work on the server side is so you can cache the results, avoid needless extra round-trips to Google and speed page generation.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic