From: <php...@li...> - 2010-09-11 16:41:24
|
Hi - OK, I suspect this may be a bit off the beaten track, but thought I would ask anywise... I have set up a Tomcat server with the php-java-bridge servlets and support, tested and the examples all work fine, so I know the basic environment works.... Now I have a webapp, and it has a .jsp file that mostly contains javascript code, along with some jsp variables and of course some html code. Within one of the javascript sections I want to use a php script, and I am going to want to do some string substitutions from some of the jsp variables. That need seems to prevent me from incorporating the php script in a separate file. So the outline of the file is something like this - ---------------- <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <%@ page import="java.io.*" %> <%@ page import="org.apache.commons.lang.*" %> <head> <% // JSP code here, for example - String url = request.getAttribute("URL").toString(); %> <script type="text/javascript"> // javascript code here... if (config.Manager) { with (config.Manager) { <?php require_once("java/Java.inc"); // <?php require_once("http://localhost:8086/mywebapp/java/Java.inc"); $IMConfig = array(); $IMConfig['images_dir'] = '<%= url%>/images'; // more php script here ?> } } </script> </head> <body> // html, javascript, jsp stuff here.... </body> </html> ------------- I have been fooling around with this, but so far it does not appear that I am getting the php script to execute. Can some kind soul help lead me to a solution? Thanks in advance... Marc... |
From: <php...@li...> - 2010-09-12 10:23:49
|
Hi, please take a look at the jsr223.jsp from the documentation download. > <?php require_once("java/Java.inc"); It's a JSP, so you need to use JSP syntax: <%@page import="javax.script.*" %> <%@page import="php.java.script.servlet.PhpCompiledHttpScriptContext" %> <%! private static final CompiledScript script; static { try { script =((Compilable)(new ScriptEngineManager().getEngineByName("php"))).compile( "<?php echo eval(java_context()->get('script')); ?>"); } catch (ScriptException e) { throw new RuntimeException("bleh!"); } } private static final String evalPHP(String arg) { 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.eval(); writer.close(); return out.toString(); } %> <script type="text/javascript"> var = <%= evalPHP("hello world"); %> Regards, Jost Bökemeier |
From: <php...@li...> - 2010-09-12 10:48:42
|
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. Regards, Jost Bökemeier |
From: <php...@li...> - 2010-09-14 20:03:57
|
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 cause the parameters of evalPHP - 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... |
From: <php...@li...> - 2010-09-14 20:15:11
|
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... > > > |
From: <php...@li...> - 2010-09-15 00:23:17
|
It should be a method. Thats why clone ls there 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... >> >> >> > > > ------------------------------------------------------------------------------ > Start uncovering the many advantages of virtual appliances > and start using them to simplify application deployment and > accelerate your shift to cloud computing. > http://p.sf.net/sfu/novell-sfdev2dev > _______________________________________________ > php-java-bridge-users mailing list > php...@li... > https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users > |
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... >>> >>> >>> >> |
From: <php...@li...> - 2010-09-12 17:34:12
|
On 9/12/2010 3:23 AM, php...@li... wrote: > Hi, > > please take a look at the jsr223.jsp from the documentation download. > > >> <?php require_once("java/Java.inc"); > It's a JSP, so you need to use JSP syntax: > > > <%@page import="javax.script.*" %> > <%@page import="php.java.script.servlet.PhpCompiledHttpScriptContext" %> > > Thanks Jost for pointing me in the right direction! One immediate question comes up however, where do I find php.java.script.servlet.PhpCompiledHttpScriptContext? It is not in any of the jar files that I picked up.... Marc... |
From: <php...@li...> - 2010-09-13 19:29:55
|
Hi it is in php-servlet.jar On 9/12/10, php...@li... <php...@li...> wrote: > On 9/12/2010 3:23 AM, php...@li... wrote: >> Hi, >> >> please take a look at the jsr223.jsp from the documentation download. >> >> >>> <?php require_once("java/Java.inc"); >> It's a JSP, so you need to use JSP syntax: >> >> >> <%@page import="javax.script.*" %> >> <%@page import="php.java.script.servlet.PhpCompiledHttpScriptContext" %> >> >> > Thanks Jost for pointing me in the right direction! One immediate > question comes up however, where do I find > php.java.script.servlet.PhpCompiledHttpScriptContext? It is not in any > of the jar files that I picked up.... > > Marc... > > > ------------------------------------------------------------------------------ > Start uncovering the many advantages of virtual appliances > and start using them to simplify application deployment and > accelerate your shift to cloud computing > http://p.sf.net/sfu/novell-sfdev2dev > _______________________________________________ > php-java-bridge-users mailing list > php...@li... > https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users > |
From: <php...@li...> - 2010-09-16 01:32:12
|
Jost, all - I have been doing more investigations into why the php-java bridge is not working as I would expect, but so far I got no joy in why it is failing... So I thought I would send in a concise version of the jsp code/file I am trying to set up, and see if you or anyone else can spot what I am doing wrong.... (this also shows the interplay between jsp variables and the Javascript/PHP scripts, which is why I am choosing to use JSP) What I am discovering, is that as expected the method evalPHP is being called (twice). The call to the function - outputJavaScript in my PHP script does indeed return a Javascript statement (via the internal call to pass_to_php_backend), which is a String variable, and I can in fact put an echo statement just before the return and see that the expected Javascript statement is produced. But what is NOT happening is that this returned string is produced in the output document, at the point of call to evalPHP. (I have placed calls to alerts to show this is indeed what is happening, as can be seen in the following code.) Thoughts? Thanks again in advance for helping me with this... Marc... <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <%@ page import="java.io.*" %> <%@ page import="org.apache.commons.lang.*" %> <%@page import="javax.script.*" %> <%@page import="php.java.script.servlet.*" %> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Example</title> <% String url = request.getAttribute("URL").toString(); String file = request.getAttribute("DocPath").toString(); String docRootDir = file.substring(0, file.lastIndexOf("/")); String serverURL = request.getAttribute("ServerURL").toString(); String contextPath = "/" + request.getAttribute("ContextPath").toString(); String Dir = request.getAttribute("Dir").toString(); %> <% // My PHP script is defined here.... String phpScript = ""; phpScript = "require_once '" + Dir + "/java/Java.inc'; \n"; phpScript += "require_once '" + Dir + "/contrib/php-utilities.php'; \n"; phpScript += "function outputJavaScript() { \n"; phpScript += "$IMConfig = array(); \n"; phpScript += "$IMConfig['images_dir'] = '" + docRootDir + "/images'; \n"; phpScript += "$IMConfig['allowed_image_extensions'] = array('jpg','gif','png'); \n"; phpScript += "return pass_to_php_backend($IMConfig); \n"; phpScript += "} \n"; phpScript += "outputJavaScript(); \n"; %> <%! private static final CompiledScript script; static { try { script =((Compilable)(new ScriptEngineManager().getEngineByName("php"))).compile( "<?php echo eval(java_context()->get('script')); ?>"); } catch (ScriptException e) { throw new RuntimeException("bleh!"); } } // private static final String evalPHP(String arg) { 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; } %> <script type="text/javascript"> url = <%= "\"" + serverURL + "\"" %> + <%= "\"" + contextPath + "\"" %>; lang = "en"; </script> <!-- <script type="text/javascript" src="../Core.js"></script> --> <script type="text/javascript" src="Loader.js"></script> <script type="text/javascript"> config = config ? config : new Backend.Config(); config.fullPage = true; // pass the configuration to plugin if (config.FileManager) { with (config.FileManager) { a = "<%= evalPHP(phpScript, request, response) %>"; if (a == "") alert("No Output"); else { alert("Output = " + a); <%= evalPHP(phpScript, request, response) %> } } } }; </script> </head> <body> <!-- Content of body not important, removed --> </body> </html> |
From: <php...@li...> - 2010-09-25 10:10:40
|
Hi, [please excuse the delay] > instance.getEngine().getContext().setWriter(writer); // wrong! reset by following line > instance.getEngine().setContext((ScriptContext)new PhpHttpScriptContext(instance.getEngine().getContext(),this,this.getServletContext(),request,response)); > I have been doing more investigations into why the php-java bridge is > not working as I would expect The PHP/Java Bridge code is correct. The decorator you've set connects the writer, reader, errorWriter to the servlet. So your code has no effect. Please see the example code I've given. BTW: For PHP/Java Bridge 6.2.1 I will rename the decorator to "PhpHttpScriptContext". Please either use your own decorator (copy PhpHttpCompiledScriptContext.java to your project) or please use the new name. The test script I've used is below: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <%@ page import="java.io.*" %> <%@ page import="org.apache.commons.lang.*" %> <%@page import="javax.script.*" %> <%@page import="php.java.script.servlet.*" %> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Example</title> <% // My PHP script is defined here.... String phpScript = ""; phpScript += "function pass_to_php_backend($ar) { \n"; phpScript += " print('something'); \n"; phpScript += " //do something useful here...\n"; phpScript += "} \n"; phpScript += "function outputJavaScript() { \n"; phpScript += "$IMConfig = array(); \n"; phpScript += "$IMConfig['allowed_image_extensions'] = array('jpg','gif','png'); \n"; phpScript += "return pass_to_php_backend($IMConfig); \n"; phpScript += "} \n"; phpScript += "outputJavaScript(); \n"; %> <%! private static final CompiledScript script; static { try { script =((Compilable)(new ScriptEngineManager().getEngineByName("php"))).compile( "<?php echo eval(java_context()->get('script')); ?>"); } catch (ScriptException e) { throw new RuntimeException("bleh!"); } } // private static final String evalPHP(String arg) { 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().setContext((ScriptContext)new PhpHttpScriptContext(instance.getEngine().getContext(),this,this.getServletContext(),request,response)); instance.getEngine().getContext().setWriter(writer); 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; } %> <script type="text/javascript"> a = '<%= evalPHP(phpScript, request, response) %>;' if (a == "") alert("No Output"); else alert("Output = " + a); <%= evalPHP(phpScript, request, response) %> </script> </head> <body> hello </body> </html> Regards, Jost Bökemeier |
From: <php...@li...> - 2010-09-20 20:26:37
|
Anyone, Jost, got any thoughts on why this PHP script is not working as I would expect it to? I am stuck until I can find a solution... Thanks... Marc.. On 9/15/2010 6:31 PM, php...@li... wrote: > Jost, all - > > I have been doing more investigations into why the php-java bridge is > not working as I would expect, but so far I got no joy in why it is > failing... So I thought I would send in a concise version of the jsp > code/file I am trying to set up, and see if you or anyone else can spot > what I am doing wrong.... (this also shows the interplay between jsp > variables and the Javascript/PHP scripts, which is why I am choosing to > use JSP) > > What I am discovering, is that as expected the method evalPHP is being > called (twice). The call to the function - outputJavaScript in my PHP > script does indeed return a Javascript statement (via the internal call > to pass_to_php_backend), which is a String variable, and I can in fact > put an echo statement just before the return and see that the expected > Javascript statement is produced. But what is NOT happening is that > this returned string is produced in the output document, at the point of > call to evalPHP. (I have placed calls to alerts to show this is indeed > what is happening, as can be seen in the following code.) > > Thoughts? Thanks again in advance for helping me with this... Marc... > > > <?xml version="1.0" encoding="UTF-8"?> > <!DOCTYPE html > PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> > <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> > <%@ page import="java.io.*" %> > <%@ page import="org.apache.commons.lang.*" %> > <%@page import="javax.script.*" %> > <%@page import="php.java.script.servlet.*" %> > > <head> > <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> > <title>Example</title> > > <% > String url = request.getAttribute("URL").toString(); > String file = request.getAttribute("DocPath").toString(); > String docRootDir = file.substring(0, file.lastIndexOf("/")); > String serverURL = request.getAttribute("ServerURL").toString(); > String contextPath = "/" + > request.getAttribute("ContextPath").toString(); > String Dir = request.getAttribute("Dir").toString(); > %> > > <% > // My PHP script is defined here.... > String phpScript = ""; > phpScript = "require_once '" + Dir + "/java/Java.inc'; \n"; > phpScript += "require_once '" + Dir + "/contrib/php-utilities.php'; \n"; > > phpScript += "function outputJavaScript() { \n"; > phpScript += "$IMConfig = array(); \n"; > phpScript += "$IMConfig['images_dir'] = '" + docRootDir + "/images'; \n"; > phpScript += "$IMConfig['allowed_image_extensions'] = > array('jpg','gif','png'); \n"; > phpScript += "return pass_to_php_backend($IMConfig); \n"; > phpScript += "} \n"; > > phpScript += "outputJavaScript(); \n"; > %> > > <%! > private static final CompiledScript script; > static { > try { > script =((Compilable)(new > ScriptEngineManager().getEngineByName("php"))).compile( > "<?php echo eval(java_context()->get('script')); ?>"); > } catch (ScriptException e) { > throw new RuntimeException("bleh!"); > } > } > // private static final String evalPHP(String arg) { > 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; > } > %> > > > <script type="text/javascript"> > url =<%= "\"" + serverURL + "\"" %> +<%= "\"" + contextPath + > "\"" %>; > lang = "en"; > </script> > > <!--<script type="text/javascript" src="../Core.js"></script> --> > <script type="text/javascript" src="Loader.js"></script> > > <script type="text/javascript"> > config = config ? config : new Backend.Config(); > config.fullPage = true; > // pass the configuration to plugin > if (config.FileManager) { > with (config.FileManager) > { > a = "<%= evalPHP(phpScript, request, response) %>"; > if (a == "") alert("No Output"); > else { > alert("Output = " + a); > <%= evalPHP(phpScript, request, response) %> > } > > } > } > }; > </script> > </head> > > <body> > <!-- Content of body not important, removed --> > </body> > </html> > > > ------------------------------------------------------------------------------ > Start uncovering the many advantages of virtual appliances > and start using them to simplify application deployment and > accelerate your shift to cloud computing. > http://p.sf.net/sfu/novell-sfdev2dev > _______________________________________________ > php-java-bridge-users mailing list > php...@li... > https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users > |
From: <php...@li...> - 2010-09-20 20:42:32
|
probably the decorator resets or reverts your changes. we wlll see On 9/20/10, php...@li... <php...@li...> wrote: > Anyone, Jost, got any thoughts on why this PHP script is not working > as I would expect it to? I am stuck until I can find a solution... > Thanks... Marc.. > > On 9/15/2010 6:31 PM, php...@li... wrote: >> Jost, all - >> >> I have been doing more investigations into why the php-java bridge is >> not working as I would expect, but so far I got no joy in why it is >> failing... So I thought I would send in a concise version of the jsp >> code/file I am trying to set up, and see if you or anyone else can spot >> what I am doing wrong.... (this also shows the interplay between jsp >> variables and the Javascript/PHP scripts, which is why I am choosing to >> use JSP) >> >> What I am discovering, is that as expected the method evalPHP is being >> called (twice). The call to the function - outputJavaScript in my PHP >> script does indeed return a Javascript statement (via the internal call >> to pass_to_php_backend), which is a String variable, and I can in fact >> put an echo statement just before the return and see that the expected >> Javascript statement is produced. But what is NOT happening is that >> this returned string is produced in the output document, at the point of >> call to evalPHP. (I have placed calls to alerts to show this is indeed >> what is happening, as can be seen in the following code.) >> >> Thoughts? Thanks again in advance for helping me with this... Marc... >> >> >> <?xml version="1.0" encoding="UTF-8"?> >> <!DOCTYPE html >> PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" >> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> >> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> >> <%@ page import="java.io.*" %> >> <%@ page import="org.apache.commons.lang.*" %> >> <%@page import="javax.script.*" %> >> <%@page import="php.java.script.servlet.*" %> >> >> <head> >> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> >> <title>Example</title> >> >> <% >> String url = request.getAttribute("URL").toString(); >> String file = request.getAttribute("DocPath").toString(); >> String docRootDir = file.substring(0, file.lastIndexOf("/")); >> String serverURL = request.getAttribute("ServerURL").toString(); >> String contextPath = "/" + >> request.getAttribute("ContextPath").toString(); >> String Dir = request.getAttribute("Dir").toString(); >> %> >> >> <% >> // My PHP script is defined here.... >> String phpScript = ""; >> phpScript = "require_once '" + Dir + "/java/Java.inc'; \n"; >> phpScript += "require_once '" + Dir + "/contrib/php-utilities.php'; \n"; >> >> phpScript += "function outputJavaScript() { \n"; >> phpScript += "$IMConfig = array(); \n"; >> phpScript += "$IMConfig['images_dir'] = '" + docRootDir + "/images'; \n"; >> phpScript += "$IMConfig['allowed_image_extensions'] = >> array('jpg','gif','png'); \n"; >> phpScript += "return pass_to_php_backend($IMConfig); \n"; >> phpScript += "} \n"; >> >> phpScript += "outputJavaScript(); \n"; >> %> >> >> <%! >> private static final CompiledScript script; >> static { >> try { >> script =((Compilable)(new >> ScriptEngineManager().getEngineByName("php"))).compile( >> "<?php echo eval(java_context()->get('script')); ?>"); >> } catch (ScriptException e) { >> throw new RuntimeException("bleh!"); >> } >> } >> // private static final String evalPHP(String arg) { >> 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; >> } >> %> >> >> >> <script type="text/javascript"> >> url =<%= "\"" + serverURL + "\"" %> +<%= "\"" + contextPath + >> "\"" %>; >> lang = "en"; >> </script> >> >> <!--<script type="text/javascript" src="../Core.js"></script> --> >> <script type="text/javascript" src="Loader.js"></script> >> >> <script type="text/javascript"> >> config = config ? config : new Backend.Config(); >> config.fullPage = true; >> // pass the configuration to plugin >> if (config.FileManager) { >> with (config.FileManager) >> { >> a = "<%= evalPHP(phpScript, request, response) %>"; >> if (a == "") alert("No Output"); >> else { >> alert("Output = " + a); >> <%= evalPHP(phpScript, request, response) %> >> } >> >> } >> } >> }; >> </script> >> </head> >> >> <body> >> <!-- Content of body not important, removed --> >> </body> >> </html> >> >> >> ------------------------------------------------------------------------------ >> Start uncovering the many advantages of virtual appliances >> and start using them to simplify application deployment and >> accelerate your shift to cloud computing. >> http://p.sf.net/sfu/novell-sfdev2dev >> _______________________________________________ >> php-java-bridge-users mailing list >> php...@li... >> https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users >> > > > ------------------------------------------------------------------------------ > Start uncovering the many advantages of virtual appliances > and start using them to simplify application deployment and > accelerate your shift to cloud computing. > http://p.sf.net/sfu/novell-sfdev2dev > _______________________________________________ > php-java-bridge-users mailing list > php...@li... > https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users > |