Meaningless Drivel is fun!
The moose likes Java in General and the fly likes Execute php from Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Execute php from Java" Watch "Execute php from Java" New topic

Execute php from Java

Melanie Walsh

Joined: Dec 14, 2004
Posts: 20
I am still trying to execute a php script from within my java class.
I have tried the following code to pass a var and nothing happens. Can anybody help? This is for my final year project, the php scrpit retrieves data form internet based on info entered in the java gui, trouble is i cant get the php script to run, i can open and read using URL object but not run, thius is the trial code im using:-

String program = "Eastenders";

public static void main(String[] args) throws Exception {

URL localScript = new URL("http://localhost/BBC2Test3.php/?program");
URLConnection phpConnection = localScript.openConnection();
} catch (MalformedURLException e) {
System.out.println("URL Failed"); // new URL() failed

} catch (IOException e) { // openConnection() failed
System.out.println("Open Connection Failed");

Greg T Robertson
Ranch Hand

Joined: Nov 18, 2003
Posts: 91
And if you execute that same script from within a browser what resutls do you get? It's probably being fed by a form from somewhere - is it a post or get?

You say it doesn't execute - but are you certain it's not executing - or are you just seeing no results? Any exceptions of any type at all?
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

without seeing all the code, I will guess that your URL string needs to look like this:

instead of this:
I agree. Here's the link:
subject: Execute php from Java
It's not a secret anymore!