<%!
/* The following code makes sure that the PHP script is generated with the servlet instance.
When the servlet is generated, a file jsp+php.jsp._cache_.php appears */
private static java.io.Reader script;
private static java.io.Reader getScript(String path) {
if(script!=null) return script;
return script=php.java.script.EngineFactory.getPhpScript(path,
new java.io.StringReader(
"<?php function f($arg) {return 1 + java_values($arg); }; ?>"));
}
%>
<%
/* Create a standard script engine */
javax.script.ScriptEngine e =
php.java.script.EngineFactory.getInvocablePhpScriptEngine (this,
application,
request,
response);
/* and connect its standard output */
e.getContext().setWriter (out);
/* evaluate the script, cache it in the file ".../jsp+php.jsp._cache_.php" */
e.eval (getScript(application.getRealPath(request.getServletPath())));
/* make the script engine invocable */
javax.script.Invocable i = (javax.script.Invocable) e;
/* and invoke its phpinfo and f() functions */
Object result = null;
result = i.invokeFunction("phpinfo", new Object[]{});
result = i.invokeFunction("f", new Object[]{new Integer(2)});
/* release the script engine, flushing its output */
e.eval ((java.io.Reader)null); // flush the output generated by invokeXXX
/* print the result from the above f() method invocation */
out.println("result from php::f(), printed from the servlet: " + result);
%>