From: <php...@li...> - 2010-09-15 03:37:53
|
On 9/14/2010 5:23 PM, php...@li... wrote: > It should be a method. Thats why clone ls there I am sorry but I don't follow you... What should be a method? My PHP script? If that is what you are referring to, then how will that affect the placement of the output from the script when it is evaluated? And how do I call it? Perhaps I need a better example to help me grok this? Keep in mind that what I am trying to accomplish is to executed an embedded multi-line PHP script inside a Javascript segment, all of which is inside a .jsp file..... At the moment the PHP script is being executed, but the output, being done via echo statements in the script (and called PHP functions) is all being placed at the beginning of the output document, not at the place where the evalPHP call is made... Also, are the changes I made to the evalPHP function correct? I presume that the first argument of evalPHP (String arg....) is the string that contains the actual script that I want to execute. I have concatenated all the PHP script lines into a single String variable and this is what I pass to evalPHP. Thanks again for all your time and help! Marc... > On 9/14/10, php...@li... > <php...@li...> wrote: >> On 9/14/2010 1:03 PM, php...@li... wrote: >> >> Darn, I misspoke, see correction below... Marc >>> On 9/12/2010 3:48 AM, php...@li... >>> wrote: >>>> Hi again, >>>> >>>> insert a >>>> >>>> instance.getEngine().setContext(new >>>> PhpCompiledHttpScriptContext(instance.getEngine().getContext(),this,application,request,response)); >>>> >>>> before calling instance.eval(). Otherwise JSR223 will use the default >>>> context, which isn't very usable in a web-context. >>> Hi Jost - Hmmmm since the method evalPHP, as you sent it to me in your >>> previous email, is declared private static final, one cannot use the >>> 'this' parameter. Do you see any problem with removing the static final >>> from the declaration? That allows this to be called in the context of >>> the instance of the servlet that is running. But doing so will then >> OOPS! I meant this to say - >>> cause the parameters of PhpCompiledHttpScriptContext >>> - application, request, and response to be undefined since this code is >>> within the Declaration section of the >>> servlet. I think the application parameter can be retrieved via a call >>> to this.getServletContext(), but the only way to get the request and >>> response parameters will be to pass them in to the evalPHP method. Do >>> you concur? I am thinking the following - >>> >>> private String evalPHP(String arg, HttpServletRequest request, >>> HttpServletResponse response) { >>> CompiledScript instance = >>> (CompiledScript)((java.security.cert.CertStoreParameters)script).clone(); >>> instance.getEngine().put("script", arg); >>> OutputStream out = new ByteArrayOutputStream(); >>> Writer writer = new OutputStreamWriter(out); >>> instance.getEngine().getContext().setWriter(writer); >>> instance.getEngine().setContext((ScriptContext)new >>> >>> PhpCompiledHttpScriptContext(instance.getEngine().getContext(),this,this.getServletContext(),request,response)); >>> try { >>> instance.eval(); >>> >>> } catch (ScriptException e) { >>> throw new RuntimeException("bleh!"); >>> } >>> try { >>> writer.close(); >>> } catch (IOException e) { >>> throw new RuntimeException("bleh!"); >>> } >>> String result = out.toString(); >>> return result; >>> } >>> >>> >>> I have gone ahead and tried this, and it almost got me to what I want. >>> But one problem remains and I don't grok the code enough to be able to >>> solve on my own, so need a bit more guidance. The PHP script that I want >>> to embed in the middle of a Javascript section generates a line of >>> Javascript that I want the servlet to write back out, at the point where >>> the call to evalPHP is made. But when I execute this jsp servlet, the >>> generated Javascript from the PHP script is being put out at the very >>> beginning of the document. (I was also surprised that the return result >>> from evalPHP is null....) >>> >>> Thanks again for all your help! Marc... >>> >>> >>> >> |