简体   繁体   中英

JSP page directive with language attribute

I read that with this attribute I can choose which scripting language to use with JSP.

For now I use Java but is there a container that is able to use Groovy, JRuby or others for generate the servlet code?

Is it correct to say that if there were a language other then Java, to use with JSP, it should compile into byte code compatible with JVM. Then the web container should be able to convert it into a servlet?

According to the jsp specification , this attribute is used to declare language used in scriptlets, expressions and declarations in the JSP page.

In JSP 2.1 (the latest specification), the only defined and required scripting language value for this attribute is java (all lowercase, case-sensitive). This is true for prior specifications.

Currently there are no containers as far as I know that supports an other language then the specification mandates. But if there is; as you said; it should compile it into a standard servlet.

If you are planning to use JRuby you may want to check Ruby on Rails; Grails for Groovy.

Briefly: there are no other scripting language that the JSP may support at the moment. But may be in the future.

I searched for the language attribute in the JSP documentation and found this:

Table JSP.1-8 Page Directive Attributes

  • Language

Defines the scripting language to be used in the scriptlets, expression scriptlets, and declarations within the body of the translation unit (the JSP page and any files included using the include directive below). In JSP 2.1, the only defined and required scripting language value for this attribute is java (all lowercase, case-sensitive). This specification only describes the semantics of scripts for when the value of the language attribute is java. When java is the value of the scripting language, the Java Programming Language source code fragments used within the translation unit are required to conform to the Java Programming Language Specification in the way indicated in Chapter JSP.9, “Scripting”. All scripting languages must provide some implicit objects that a JSP page author can use in declarations, scriptlets, and expressions. The specific objects that can be used are defined in Section JSP.1.8.3, “Implicit Objects”.” All scripting languages must support the Java Runtime Environment (JRE). All scripting languages must expose the Java technology object model to the script environment, especially implicit variables, JavaBeans component properties, and public methods. Future versions of the JSP specification may define additional values for the language attribute and all such values are reserved. It is a fatal translation error for a directive with a non-java language attribute to appear after the first scripting element has been encountered. Default is java.

Not that I know of - the closest I can find (and have used) is http://groovy.codehaus.org/GSP is now part of grails . I garner that this is better than jsp when used in conjunction with grails!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM