File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Webpage source code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Webpage source code" Watch "Webpage source code" New topic

Webpage source code

Bob Woodr

Joined: Feb 09, 2006
Posts: 3
Is there any way to get a webpages source code using jsp? For example I want my jsp page to get the source code of lets say and write it to a file, how can I do this? thanks.
Scott Dunbar
Ranch Hand

Joined: Sep 23, 2004
Posts: 245
Your best bet would be to look at Apache Commons HttpClient library. This makes it very simple to get a URL. It also handles things like cookies and authentication.

<a href="" target="_blank" rel="nofollow">Java forums using Java software</a> - Come and help get them started.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42959
And of you want to process the page you got, have a look into HttpUnit (on SourceForge), which will give you a DOM view of the page. That way you can use the DOM API or XPath to get at the contents of the page.
I agree. Here's the link:
subject: Webpage source code
jQuery in Action, 3rd edition