java JSTL和表达式语言的确切区别和关系

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15848251/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 21:02:18  来源:igfitidea点击:

Exact difference and relation between JSTL and Expression Language

javajspjakarta-eejstlel

提问by Suresh Atta

After reading the Q&A How to avoid Java code in JSP files?I stopped coding with scriptlets.

阅读问答后如何避免 JSP 文件中的 Java 代码?我停止了使用 scriptlet 编码。

So started reading JSTLand got a doubt that I found JSTL is have a relation with EL.

所以开始阅读JSTL并怀疑我发现 JSTL 与EL有关系 。

But I am not getting the exact relation between them.

但我没有得到它们之间的确切关系。

Here I got the code from here

在这里,我从这里得到了代码

 <c:set var="test" value="JSTL Core Tags"></c:set>
 <c:out value="${test}"></c:out>

I know <c:setis a JSP tag and ${test}is Expression language ..

我知道<c:set是一个 JSP 标签,${test}是表达式语言..

My confusions are

我的困惑是

  1. Won't working with JSTLalone work? Does it always need the support of EL? If not always needed, how in the above case?

  2. How to simply use the Expression language without JSTL tags?

  1. 会不会有工作JSTL单独工作?它总是需要的支持EL吗?如果不是总是需要,在上述情况下如何?

  2. 如何在没有 JSTL 标签的情况下简单地使用表达式语言?

回答by JB Nizet

The EL, initially, has been designed to be used inside attributes of the JSTL tags, and any other custom tag you might want to use or write yourself.

EL 最初被设计为在 JSTL 标记的属性内使用,以及您可能想要使用或自己编写的任何其他自定义标记。

A later version of the JSP spec has allowed using the EL directly inside the JSPs, but this doesn't mean the JSTL isn't useful anymore. The only thing you can do with EL directly in the JSP is to write some value to the response like for example

JSP 规范的更高版本允许直接在 JSP 内部使用 EL,但这并不意味着 JSTL 不再有用。您可以直接在 JSP 中使用 EL 做的唯一一件事就是向响应写入一些值,例如

${user.id}

which would write the ID of the user bean. If you want tests, loops, HTML escaping, URLs, date an number formatting, etc., you still need to use the JSTL.

它将写入用户 bean 的 ID。如果您想要测试、循环、HTML 转义、URL、日期和数字格式等,您仍然需要使用 JSTL。