Hi Chris,
> On 10/13/19 08:40, Rony G. Flatscher (Apache) wrote:
... cut ...
> > Or with other words, what is needed to allow "<%@page
> > language="rexx"%>" ("rexx" being a javax.script.Engine, could be
> > "javascript", "jython", "php", "jacl", "jlog", ...), which might
> > be the easiest for the script language programmers?
>
> I think your question *does* have an actual answer, but I'm going to
> put it off for one more post, because I think this is the better
> answer to your question: "It doesn't matter what is needed, because
> it's a bad idea and shouldn't be done, anyway."
>
> If you agree that better tag libraries are needed more than
> scripting-style code blocks, then why persist in trying to build-out
> technology to enable scripting-style code blocks?
>
> If I were king, I'd deprecate the "language" attribute in JSP and
> abolish scriptlets *entirely*, making this whole question moot.
>
> You can also resurrect the BSF-style tag library and allow any kind of
> scripting in there -- even mixed-language pages! -- that you want,
> which I also think is a bad idea.

Maybe an example makes clear what I would be after, using two JSP samples [1], 
[2] from the net that
serve as tutorials for JSPs being deployed via Tomcat:

  * [1] shows the following sample JSP page:
      o the code uses Java:

        <%@ page language="java" contentType="text/html"%>
        <%@ page import="java.text.*,java.util.*" %>
        <html>
        <head>
        <title>Date JSP</title>
        </head>
        <% SimpleDateFormat sdf=new SimpleDateFormat("MM/dd/yyyy"); %>
        <body>
        <h1>Welcome to Tomcat! Today is <%= sdf.format(new Date()) %></h1>
        </body>
        </html>

      o the above JSP should be replacable by e.g. using the RexxScriptEngine 
(implementing
        javax.script.ScriptEngine) hence with the following Rexx code [3] 
replacing the Java code above:

        <%@ page language="rexx" contentType="text/html"%>
        <html>
        <head>
        <title>Date JSP</title>
        </head>
        <body>
        <h1>Welcome to Tomcat! Today is <%= date("usa") %></h1>
        </body>
        </html>


  * [2] shows the following sample JSP page:
      o the code uses Java:

        <%@ page contentType="text/html;charset=UTF-8" language="java" %>
        <%@ page import="java.util.Date" %>
        <html>
        <head>
            <title>Hello World</title>
        </head>
        <body>
            <h1><% out.print("Hello World!"); %></h1>
            Today is: <% out.print(new Date().toString()); %>
        </body>
        </html>

      o the above JSP should be replacable by e.g. using the RexxScriptEngine 
(implementing
        javax.script.ScriptEngine) hence with the following Rexx code [3] 
replacing the Java code above:

        <%@ page contentType="text/html;charset=UTF-8" language="rexx" %>
        <html>
        <head>
            <title>Hello World</title>
        </head>
        <body>
            <h1><% out~print("Hello World!") %></h1>
            Today is: <% out~print(date()) %>
        </body>
        </html>

If the JSP samples [1], [2] are good for Java, than the suggested alternatives 
above (using Rexx for
the sake of the example) would be good for any other (Java scripting) language 
as well?

Such a solution would allow non-Java-programmers to create and deploy JSPs 
written in their language
of choice [4] using Tomcat without a need to know Java.

---rony

[1] "How to Run a JSP Program in Apache Tomcat (Windows)", URL:
<https://www.webucator.com/how-to/how-run-jsp-program-apache-tomcat-windows.cfm>

[2] "HelloWorld from Java jsp with OpenJDK 11 packaged Maven war and deploy on 
Tomcat 9", URL:
<https://github.com/jbilander/HowTos/wiki/HelloWorld-from-Java-jsp-with-OpenJDK-11-packaged-Maven-war-and-deploy-on-Tomcat-9>

[3] Here ooRexx ("open object Rexx") is being employed which is an interpreted, 
dynamically typed
and (like Smalltalk) message based language with a very easy syntax, yet quite 
powerful. The message
operator is the tilde (~), left is the receiver, right the message name with 
optional arguments
(conceptually the receiver looks up the method that has the same name as the 
received message,
invokes it and returns the result, if any). Here the built-in-function date() 
gets used to get and
display the current day.

[4] The idea would be to create a generic support by using javax.script such 
that all languages for
which javax.script.ScriptEngine implementations exist could be deployed by 
merely changing the
language attribute from "java" to the registered name of the scripting language 
one wishes to use.
Such a javax.script support would allow for supplying e.g. the request and 
response objects as
arguments for each invocation in a standardized way by placing them in the
ScriptContext.ENGINE_SCOPE Bindings using e.g. ScriptEngine.ARGV as a key (a 
constant resolving to
"javax.script.argv") for the Java array that contains the arguments, optionally 
adding "out" and the
like into the ScriptContext.ENGINE_SCOPE Bindings etc. (like submitting the 
name of the JSP file for
debugging via ScriptContext.FILENAME, ...)


Reply via email to