title: How to run java code (.class) using php and display on the same web page
body: <p>I am trying to run a java program using php script.</p>
  <p>First, php displays a form where users input two values: Price and Sales Tax Rate.
  Next, it extracts the values and passes it to a java program (precompiled as .class file).</p>
  <p>I am uncertain as to where the output is printed if at all the java code is working. My ultimate goal is to display the result to the user in an html page.</p>
  <p>I upload my file contents to my web server and try to run it from there.</p>
  <h1>update:</h1>
  <p>How can I use shell_exec or exec to run java code? I need to pass the parameters (price, salesTax) to shell_exec. Where is the returned output stored?</p>
  <p><strong>PHP code:</strong></p>
  <pre><code>&gt; &lt;?php
  &gt; 
  &gt; $salesTaxForm = &lt;&lt;&lt;SalesTaxForm
  &gt; 
  &gt; &lt;form action=&quot;SalesTaxInterface.php&quot; method=&quot;post&quot;&gt;
  &gt; 
  &gt;    Price (ex. 42.56):&lt;br&gt;
  &gt; 
  &gt;    &lt;input type=&quot;text&quot; name=&quot;price&quot; size=&quot;15&quot; maxlength=&quot;15&quot;
  &gt; value=&quot;&quot;&gt;&lt;br&gt;
  &gt; 
  &gt;    Sales Tax rate (ex. 0.06):&lt;br&gt;
  &gt; 
  &gt;    &lt;input type=&quot;text&quot; name=&quot;tax&quot; size=&quot;15&quot; maxlength=&quot;15&quot;
  &gt; value=&quot;&quot;&gt;&lt;br&gt;
  &gt; 
  &gt;    &lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Calculate!&quot;&gt;
  &gt; 
  &gt;    &lt;/form&gt;
  &gt; 
  &gt; SalesTaxForm;
  &gt; 
  &gt; if (! isset($submit)) :
  &gt; 
  &gt;    echo $salesTaxForm;
  &gt; 
  &gt; else :    $salesTax = new Java(&quot;SalesTax&quot;);
  &gt; 
  &gt;    $price = (double) $price;    $tax = (double) $tax;
  &gt; 
  &gt;    print $salesTax-&gt;SalesTax($price, $tax);
  &gt; 
  &gt; endif;
  &gt; 
  &gt; ?&gt;
  </code></pre>
  <p><strong>Java Code:</strong></p>
  <blockquote>
  <pre><code>import java.util.*;
  import java.text.*;
  
  public class SalesTax {
  public String SalesTax(double price, double salesTax) 
  {
  
      double tax = price * salesTax;
  
      NumberFormat numberFormatter;
  
      numberFormatter = NumberFormat.getCurrencyInstance();
  
      String priceOut = numberFormatter.format(price);
  
      String taxOut = numberFormatter.format(tax);
  
      numberFormatter = NumberFormat.getPercentInstance();
  
      String salesTaxOut = numberFormatter.format(salesTax);
  
      String str = &quot;A sales Tax of &quot; + salesTaxOut +
  
                   &quot; on &quot; + priceOut + &quot; equals &quot; + taxOut + &quot;.&quot;;
  
      return str;
  
      }
  
  }
  </code></pre>
  </blockquote>