Link to home
Start Free TrialLog in
Avatar of blainehilton
blainehilton

asked on

Requesting a URL

I have an application where I need a java program that will open up a URL and cause the web page to be ran.  The java program will be opening a web page that is itself a PHP script.

The code that I have been playing around with is like this:
------------------------------------------------------------------------
import java.net.*;
import java.io.*;

class Link {
      public static void main(String[] args) {
            try
               {
                       URL url = new URL("http://192.168.5.100/index.php");
                        URLConnection connection = url.openConnection();
               }
               catch (Exception e)
               {
                        System.out.println(e.toString());
               }
      }
}
-----------------------------------------------------------------------

Any help would be appreciated.

Also I am using an older version of Java if that matters, I believe it is version 1.2.2.  Please explain your solutions in detail as I have very little Java knowledge.

--
Thanks in Advance
Blaine
SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
if you want to actually render the html page you'll need to use JEditorPane.
Let me know if you need more details.
Avatar of blainehilton
blainehilton

ASKER

Thank you for your fast response, no I do not need to view the page, just have it run the PHP.

I ran the code you sent and it complied fine but when I ran it I received an error saying "java.net.MalformedURLException".  This is the same error I was having with my example.
strange it looks alright, is the URL you are using the same as what is posted here?
The URL is pretty much the same, but is different.  It is an IP address and not a hostname and I am using the http:// and the page does exist, and the device can ping the server.

Does it matter that this is running on a TINI Module?  (http://www.ibutton.com/TINI/index.html)

When I run it with the command "java Link.class" from the DOS prompt I receive a different error.  The dos prompt gives me:

Exception in thread "main" java.lang.NoClassDefFoundError: Link/class

> When I run it with the command "java Link.class"

should be:

java Link
> The URL is pretty much the same, but is different.

what is it exactly then?
Using the command "java Link" it worked great, however it is not working on the TINI.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial