Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to run java code (.class) using php and display on the same web page
    primarykey
    data
    text
    <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="SalesTaxInterface.php" method="post"&gt; &gt; &gt; Price (ex. 42.56):&lt;br&gt; &gt; &gt; &lt;input type="text" name="price" size="15" maxlength="15" &gt; value=""&gt;&lt;br&gt; &gt; &gt; Sales Tax rate (ex. 0.06):&lt;br&gt; &gt; &gt; &lt;input type="text" name="tax" size="15" maxlength="15" &gt; value=""&gt;&lt;br&gt; &gt; &gt; &lt;input type="submit" name="submit" value="Calculate!"&gt; &gt; &gt; &lt;/form&gt; &gt; &gt; SalesTaxForm; &gt; &gt; if (! isset($submit)) : &gt; &gt; echo $salesTaxForm; &gt; &gt; else : $salesTax = new Java("SalesTax"); &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 = "A sales Tax of " + salesTaxOut + " on " + priceOut + " equals " + taxOut + "."; return str; } } </code></pre> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload