You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by "Rony G. Flatscher (Apache)" <ro...@apache.org> on 2019/10/17 10:00:49 UTC

Questions ad JSP/Jasper implementation in Tomcat ...

Being interested in analyzing what is needed to enable Tomcat JSP's to be deployable with any Java
scripting languages (i.e. with javax.script.ScriptEngines) instead of Java.

Motivation: there are programmers who are not able to program in Java, but have broad expertise in
programming with other languages like Javascript, PHP, Rexx, Python, etc. If such programmers could
devise JSPs using their programming language of choice instead of (or in addition to) Java, they
would become able to take advantage of Tomcat.

Idea: since Java 6 the javax.script package defines a Java scripting framework which can be used to
generically create the Java program necessary to deploy the code in JSPs. E.g. the 'request' and
'response' objects could be supplied as arguments via the ScriptContext.ENGINGE_SCOPE Bindings in a
Java array named ScriptEngine.ARGV, but also objects like 'out' could be made available to all Java
scripting languages. This in essence should allow any (JVM) langugage implementing a
javax.script.ScriptEngine to be used as a programming language in a JSP by merely denoting its name
in "<%@ page language="LANGUAGE" contentType="text/html"%>, where LANGUAGE could then be e.g.
"javascript", "jython", "netrexx", "rexx", ... instead of "java".

The question(s):

  * Where would one find a document/tutorial with a conceptual overview of processing a JSP file?
  * Which class(es) are used to process JSPs with the language attribute set to "java" in the
    current implementation of Tomcat, assuming that it would be feasible to subclass (or create
    alternatives of) those class(es) to add generic support for JSR223 (javax.script.ScriptEngine)?

Any hints, warnings, pointers highly appreciated!

---rony



Re: Questions ad JSP/Jasper implementation in Tomcat ...

Posted by "Rony G. Flatscher (Apache)" <ro...@apache.org>.
On 18.10.2019 13:32, Rony G. Flatscher (Apache) wrote:
> Thank you very much for your remarks and pointers, Mark!
>
> ---rony
>
> P.S.: Not sure as of yet, what scope it should be. The idea would be to allow any of the Java script
> languages to be used. Currently the naive assumption is that one could redirect the script's stdout
> to the servlet's 'out' object (by using ScriptContext.setWriter(out)) and using ScriptEngineFactory
> helper methods getOutputStatement(...), getProgram(...) and maybe getMethodCallSyntax(...) for
> creating the appropriate script program from the JSP that then gets dispatched via
> ScriptEngine.eval(...) from the created Java program.

... cut ...

Just to give an idea what the Java code employing javax.script might look like (untested), assuming
that from the JSP the respective script program got created (referred to by "String
scriptFromJSP=..." in the Java snippet to be generated below):

    import javax.script.*;

    ... cut ...

                // the scriptCode value is created when transforming the JSP to its script code
    representation using
                // ScriptEngineFactory utility methods
            String scriptFromJSP="...script created from JSP ...";
            try
            {
                    // create a ScriptContext for this run
                ScriptContext sc=new SimpleScriptContext();
                sc.setWriter(out);      // set stdout to 'out'

                    // get its ENGINE_SCOPE Bindings
                Bindings     engineScope=sc.getBindings(ScriptContext.ENGINE_SCOPE);
                    // set JSP file name for the script
                engineScope.put(ScriptEngine.FILENAME, jspFileName);
                    // define arguments for the script program
                engineScope.put(ScriptEngine.ARGV, new Object[]{request,response});

                    // set JSP objects
                engineScope.put("application", application);
                engineScope.put("config", config);
                engineScope.put("out", out);
                engineScope.put("pageContext", pageContext);
                engineScope.put("request" , request);
                engineScope.put("response", response);

                    // get ScriptEngine, evaluate (run) script program
                ScriptEngineManager sem=new ScriptEngineManager();
                ScriptEngine se=sem.getEngineByName("LANGUAGE_NAME");  // language name used for JSP
    "language" attribute in the page directive
                    // run (execute) the script with the ScriptContext
                Object res=se.eval(scriptFromJSP, sc);  // run the script
            }
            catch (ScriptException sexc)   // an error occurred
            {
                sexc.printStackTrace();
                System.exit(-1);
            }

    ... cut ...

---rony


Re: Questions ad JSP/Jasper implementation in Tomcat ...

Posted by "Rony G. Flatscher (Apache)" <ro...@apache.org>.
Thank you very much for your remarks and pointers, Mark!

---rony

P.S.: Not sure as of yet, what scope it should be. The idea would be to allow any of the Java script
languages to be used. Currently the naive assumption is that one could redirect the script's stdout
to the servlet's 'out' object (by using ScriptContext.setWriter(out)) and using ScriptEngineFactory
helper methods getOutputStatement(...), getProgram(...) and maybe getMethodCallSyntax(...) for
creating the appropriate script program from the JSP that then gets dispatched via
ScriptEngine.eval(...) from the created Java program.


On 17.10.2019 15:41, Mark Thomas wrote:
> On 17/10/2019 11:00, Rony G. Flatscher (Apache) wrote:
>> Being interested in analyzing what is needed to enable Tomcat JSP's to
>> be deployable with any Java scripting languages (i.e. with
>> javax.script.ScriptEngines) instead of Java.
> A potentially huge amount of work if you propose replicating JSP
> functionality (tag libraries, EL support, etc.) but with a different
> language.
>
>> Motivation: there are programmers who are not able to program in Java,
>> but have broad expertise in programming with other languages like
>> Javascript, PHP, Rexx, Python, etc. If such programmers could devise
>> JSPs using their programming language of choice instead of (or in
>> addition to) Java, they would become able to take advantage of Tomcat.
>>
>> Idea: since Java 6 the javax.script package defines a Java scripting
>> framework which can be used to generically create the Java program
>> necessary to deploy the code in JSPs. E.g. the 'request' and 'response'
>> objects could be supplied as arguments via the
>> ScriptContext.ENGINGE_SCOPE Bindings in a Java array named
>> ScriptEngine.ARGV, but also objects like 'out' could be made available
>> to all Java scripting languages. This in essence should allow any (JVM)
>> langugage implementing a javax.script.ScriptEngine to be used as a
>> programming language in a JSP by merely denoting its name in "<%@ page
>> language="LANGUAGE" contentType="text/html"%>, where LANGUAGE could then
>> be e.g. "javascript", "jython", "netrexx", "rexx", ... instead of "java".
>>
>> The question(s):
>>
>>   * Where would one find a document/tutorial with a conceptual overview
>>     of processing a JSP file?
> The JSP specification.
> https://cwiki.apache.org/confluence/display/tomcat/Specifications
>
>>   * Which class(es) are used to process JSPs with the language attribute
>>     set to "java" in the current implementation of Tomcat, assuming that
>>     it would be feasible to subclass (or create alternatives of) those
>>     class(es) to add generic support for JSR223 (javax.script.ScriptEngine)?
> org.apache.jasper.*
>
> Mark



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: Questions ad JSP/Jasper implementation in Tomcat ...

Posted by Mark Thomas <ma...@apache.org>.
On 17/10/2019 11:00, Rony G. Flatscher (Apache) wrote:
> Being interested in analyzing what is needed to enable Tomcat JSP's to
> be deployable with any Java scripting languages (i.e. with
> javax.script.ScriptEngines) instead of Java.

A potentially huge amount of work if you propose replicating JSP
functionality (tag libraries, EL support, etc.) but with a different
language.

> Motivation: there are programmers who are not able to program in Java,
> but have broad expertise in programming with other languages like
> Javascript, PHP, Rexx, Python, etc. If such programmers could devise
> JSPs using their programming language of choice instead of (or in
> addition to) Java, they would become able to take advantage of Tomcat.
> 
> Idea: since Java 6 the javax.script package defines a Java scripting
> framework which can be used to generically create the Java program
> necessary to deploy the code in JSPs. E.g. the 'request' and 'response'
> objects could be supplied as arguments via the
> ScriptContext.ENGINGE_SCOPE Bindings in a Java array named
> ScriptEngine.ARGV, but also objects like 'out' could be made available
> to all Java scripting languages. This in essence should allow any (JVM)
> langugage implementing a javax.script.ScriptEngine to be used as a
> programming language in a JSP by merely denoting its name in "<%@ page
> language="LANGUAGE" contentType="text/html"%>, where LANGUAGE could then
> be e.g. "javascript", "jython", "netrexx", "rexx", ... instead of "java".
> 
> The question(s):
> 
>   * Where would one find a document/tutorial with a conceptual overview
>     of processing a JSP file?

The JSP specification.
https://cwiki.apache.org/confluence/display/tomcat/Specifications

>   * Which class(es) are used to process JSPs with the language attribute
>     set to "java" in the current implementation of Tomcat, assuming that
>     it would be feasible to subclass (or create alternatives of) those
>     class(es) to add generic support for JSR223 (javax.script.ScriptEngine)?

org.apache.jasper.*

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org