Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Execute php from Java

 
Melanie Walsh
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
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 {
try{

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
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
without seeing all the code, I will guess that your URL string needs to look like this:

instead of this:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic