This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 60774
    
  65

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: 60774
    
  65

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: 60774
    
  65

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: 41089
    
  44
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: 60774
    
  65

In a JSP, look into <c:import>.
 
 
subject: Is there a way to read HTML into a string from a URL
 
Similar Threads
Instantiating URL from Html Content Stored in a String
sending back a URL
Reading HTML using JAVA
Passing a HTML String into the JEditorPane rather than the File name ???
parsing url content into string