Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Execute php from Java

 
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");
}

}
 
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?
 
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • 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:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!