php.java.script.servlet
Class PhpServletLocalScriptEngine
java.lang.Object
javax.script.AbstractScriptEngine
php.java.script.SimplePhpScriptEngine
php.java.script.PhpScriptEngine
php.java.script.servlet.PhpServletLocalHttpServerScriptEngine
php.java.script.servlet.PhpServletLocalScriptEngine
- All Implemented Interfaces:
- java.io.Closeable, ScriptEngine
- Direct Known Subclasses:
- PhpServletScriptEngine
public class PhpServletLocalScriptEngine
- extends PhpServletLocalHttpServerScriptEngine
A PHP script engine for Servlets. See ContextLoaderListener for details.
In order to evaluate PHP methods follow these steps:
- Create a factory which creates a PHP script file from a reader using the methods from
EngineFactory:
private static File script;
private static final File getHelloScript() {
if (script!=null) return script;
String webCacheDir = ctx.getRealPath(req.getServletPath());
Reader reader = new StringReader ("<?php echo 'hello from PHP'; ?>");
return EngineFactory.getPhpScript(webCacheDir, reader);
}
- Acquire a PHP script engine from the
EngineFactory:
ScriptEngine scriptEngine = EngineFactory.getPhpScriptEngine(this, ctx, req, res);
- Create a FileReader for the created script file:
Reader readerHello = EngineFactory.createPhpScriptFileReader(getHelloScript());
- Connect its output:
scriptEngine.getContext().setWriter (out);
- Evaluate the engine:
scriptEngine.eval(readerHello);
- Close the reader:
readerHello.close();
|
Constructor Summary |
PhpServletLocalScriptEngine(javax.servlet.Servlet servlet,
javax.servlet.ServletContext ctx,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
java.lang.String protocol,
int port)
|
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
PhpServletLocalScriptEngine
public PhpServletLocalScriptEngine(javax.servlet.Servlet servlet,
javax.servlet.ServletContext ctx,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
java.lang.String protocol,
int port)
throws java.net.MalformedURLException
- Throws:
java.net.MalformedURLException