Google Answers Logo
View Question
 
Q: How do I call a Java servlet from PHP? ( No Answer,   0 Comments )
Question  
Subject: How do I call a Java servlet from PHP?
Category: Computers > Programming
Asked by: g8z-ga
List Price: $10.00
Posted: 02 Jun 2003 15:32 PDT
Expires: 02 Jun 2003 17:17 PDT
Question ID: 212171
Hello,

I have a PHP page and a 'Hello World' servlet. Here is the content of
both:

PHP code:

<? 

print "I am now calling the servlet...<p>";

exec( "http://ip_address:8080/HelloWorld" );

?>


Java code:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloWorld extends HttpServlet {

  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
                    throws IOException, ServletException
  {
     response.setContentType("text/html");
     PrintWriter out = response.getWriter();
     out.println("Hello World!");
  }
} 


The servlet works fine by itself (running on Apache server w/ Tomcat
4.1, accessed by the url: http://ip_address:8080/HelloWorld). However,
I cannot seem to call the servlet from the PHP code. I.e., what I want
is for the output of the PHP to be:


I am now calling the servlet...

Hello World!


I am using PHP 4.3.1 and I have the Java extension enabled, although
I would rather not use them because everything that I've read about
this extension suggests that it's very unstable and still
experimental. I'd prefer to use an exec() statement or something else,
but nothing that I've tried so far works.

I've also tried rewriting the servlet as a stand-alone Java
application (with a main, etc.), and calling...

exec( "java D:/path/to/java/app/HelloWorld" ) 

and also...

`java "D:/path/to/java/app/HelloWorld"`

but nothing seems to work. The idea situation would be to call a
servlet rather than a Java app, but I would consider either a solution
to my problem.

Any help would be great.

Thanks,
Darren
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy