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 > |