I need to run a javascript page from my app and receive the page that results from the script on a String. This is my code:

try {
           URL testurl = new URL("http://www.site.com/page.html");
            try {
                
                String s=testurl.getContent().toString();
                System.out.println(s);
            } catch (IOException ex) {
                Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
            }
           
        }
        catch (MalformedURLException e) {
        }

However this only results in stuff like sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@1ce669e,sun.net.www.protocol.http.HttpURLConnection etc..
I also tried

try
{
URL                url; 
URLConnection      urlConn; 
DataInputStream    dis;

url = new URL("http://www.site.com/page.html");

urlConn = url.openConnection(); 
urlConn.setDoInput(true); 
urlConn.setUseCaches(false);

dis = new DataInputStream(urlConn.getInputStream()); 
String s; 

   
while ((s = dis.readLine()) != null)
{ 
   System.out.println(s);
} 
  dis.close(); 
  
}

catch (MalformedURLException mue) {} 
catch (IOException ioe) {}

This gives me the pure HTML code.

only results in stuff like sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@1ce669e,sun.net.www.protocol.http.HttpURLConnection

Is that the output from the toString() call? Looks like info about the class object your created.
What did you expect to see for a URL object?

This gives me the pure HTML code.

Does that include the javascript code?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.