aspose file tools*
The moose likes Servlets and the fly likes Is there a way to read HTML into a string from a URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Is there a way to read HTML into a string from a URL" Watch "Is there a way to read HTML into a string from a URL" New topic
Author

Is there a way to read HTML into a string from a URL

Fritz Largosa
Ranch Hand

Joined: Sep 12, 2005
Posts: 70
For example I want a method which accepts a url and returns the html source of the target page. Anybody know if this can be done? Any documentations I can read or sample codes? I do not seem to find any information regarding this.

Pseudocode:

String html_source = method_get_html_source("http://www.my_page/page1.html");
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61221
    
  66

Yes, but as this has nothing to do with JSP, I'll first move this to the Servlets forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61221
    
  66

Investigate the URL and URLConnection classes, or save yourself some trouble and look up the HttpClient project.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61221
    
  66

Or, are you really trying to do this from a JSP rather than with java code? (and without java code in a JSP which is a no-no)
Fritz Largosa
Ranch Hand

Joined: Sep 12, 2005
Posts: 70
Ok I will look that up, I can use either servlet or JSP. Thanks.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41865
    
  63
It could be as simple as:



Ping & DNS - my free Android networking tools app
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61221
    
  66

In a JSP, look into <c:import>.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is there a way to read HTML into a string from a URL