具有语言属性的 JSP 页面指令
我读到通过这个属性我可以选择使用哪种脚本语言 与JSP。
目前我使用 Java,但是否有一个容器可以使用 Groovy、JRuby 或其他容器 用于生成 servlet 代码?
如果有一种除 Java 之外的语言可以与 JSP 一起使用,这样说是否正确? 它应该编译成与 JVM 兼容的字节代码。那么web容器应该能够将其转换成servlet吧?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据jsp规范,该属性用于声明jsp中使用的语言JSP 页面中的 scriptlet、表达式和声明。
在 JSP 2.1(最新规范)中,唯一定义且必需的脚本语言
该属性的值为 java(全部小写,区分大小写)。这对于先前的规范来说是正确的。
据我所知,目前还没有容器支持规范规定的其他语言。但如果有的话;正如你所说;它应该将其编译成标准 servlet。
如果您计划使用 JRuby,您可能需要检查 Ruby on Rails; Groovy 的 Grails。
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.
据我所知,我能找到(并使用过)的最接近的是 http://groovy.codehaus.org/ GSP 现在是 grails 的一部分。我发现当与 grails 结合使用时,这比 jsp 更好!
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!
简而言之:目前 JSP 不支持其他脚本语言。但可能是在未来。
我在 JSP 文档中搜索了语言属性,发现了这个:
表 JSP.1-8 页面指令属性
定义要在翻译单元主体(JSP)内的 scriptlet、表达式 scriptlet 和声明中使用的脚本语言页面以及使用下面的 include 指令包含的任何文件)。
在 JSP 2.1 中,该属性唯一定义且必需的脚本语言值是 java(全部小写,区分大小写)。本规范仅描述当 language 属性值为 java 时脚本的语义。
当java是脚本语言时,翻译单元中使用的Java编程语言源代码片段需要符合Java编程语言规范,如JSP.9“脚本”中所示。
所有脚本语言都必须提供一些 JSP 页面作者可以在声明、scriptlet 和表达式中使用的隐式对象。可以使用的具体对象在 JSP.1.8.3 节“隐式对象”中定义。
所有脚本语言都必须支持 Java 运行时环境 (JRE)。所有脚本语言都必须向脚本环境公开 Java 技术对象模型,尤其是隐式变量、JavaBeans 组件属性和公共方法。
JSP 规范的未来版本可能会为语言属性定义附加值,并且所有这些值都被保留。
在遇到第一个脚本元素之后出现具有非 java 语言属性的指令是致命的翻译错误。
默认是java。
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
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.