Latest

Archive

Community news

C++

Communities and Content

Databases

Editorials

Emacs

General

HTML

Java

Notices

PHP

XML

Apache

C++

Database

General

HTML

Java

Javascript

Linux

Object oriented programming

Open source

Perl

PHP

Python

Ruby

SOAP

XML

Suggest a link

Advertise on zez

Contribute

Contact us

About zez


Interfacing with Java from PHP



Source listing


The full source code for the example is listed below. For a working example click here


<html>
 <head>
  <title>The fantastic java calculator</title>
 </head>

 <body>

<?php
    
$result = 0;
if( isset( $number1 ) && isset( $number2 ) )
{
    $calc = new Java( "eZCalc" );
    setType( $number1, "double" );
    setType( $number2, "double" );
    $calc->setA( $number1 );
    $calc->setB( $number2 );
    $operator = "";
    switch( $calctype )
    {
        case( "add" ):
            $result = $calc->add();
            $operator = "+";
            break;
        case( "sub" ):
            $result = $calc->subtract();
            $operator = "-";
            break;
        case( "mul" ):
            $result = $calc->multiply();
            $operator = "*";
            break;
        case( "div" ):
            $result = $calc->divide();
            $operator = "/";
            break;
    }

    $stack .= "$number1 $operator $number2 = $result<br>";
    print( "<h2>$stack</h2>" );
}


?>
        <h1>Type two numbers:</h1>
  <form action="ezcalc.php" method="post">
  <table bgcolor="#eeeeee" cellspacing="0" cellpadding="3" border="0">
            <tr>
                <td>
                    Number 1:
                </td>
                <td>
                    Calculation method:
                </td>
                <td>
                    Number 2:
                </td>
            </tr>
            <tr>
                <td>
                    <input type="text" name="number1">
                </td>
                <td>
                    <select name="calctype">
                        <option value="add">Add</option>
                        <option value="sub">Subtract</option>
                        <option value="mul">Multiply</option>
                        <option value="div">Divide</option>
                    </select>
                </td>
                <td>
                    <input type="text" name="number2">
                </td>
            </tr>
        </table>
        <input type="Submit" value="Calculate">
        <input type="hidden" value="<?php print( $stack ) ?>" name="stack">
        </form>
    </body>
</html>



<< Previous page | 1 | 2 | 3 | < 4 > | 5 | Next page >> | Printer-friendly page |

Comment List


There are no comments.


Forgot your password?

Register a new user

Results

Polls