Skip to content
Advertisement

Opening a full web page

Is there a way of opening a full web page using Java, I have to check the time taken in opening full web page in a Java user end application, I have tried this code:

    URL ur = new URL("http://www.google.com/");
    HttpURLConnection yc =(HttpURLConnection) ur.openConnection();
    BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
    String inputLine;
    while ((inputLine = in.readLine()) != null) 
    System.out.println(inputLine);
    in.close();

but this gives me the source code of the url… that’s useless for me!

as I need to record the time taken by a webpage to load on my desktop by making a Java application.

Everything is on client site!

Advertisement

Answer

Yeah home is right that should do the trick. But this way is much more simpler… Although a bit erroneous it should serve fine for benchmark purposes.

JEditorPane editorPane = new JEditorPane();
editorPane.setPage(new URL("http://www.google.com"));

The scripts are still rendered on the screen if you just use this snippet, although it can be worked around I don’t think you will need to bother with that since you need to just benchmark loading time… However the results may be varying very slightly since it doesn’t take time to run the JavaScript.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement