Struts 2和带有EL的Spring-打印变量的不同类型是什么 [英] Struts 2 and Spring with EL - What are the different types of printing a variable

查看:69
本文介绍了Struts 2和带有EL的Spring-打印变量的不同类型是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是EL的新手(特别是Struts 2)。我正在更新当前代码,并且看到了不同类型的条目。有什么区别?

I am obliviously new to EL (with Struts 2 specifically). I am updating the current code and I see different types of entries. Whats the difference?

<s:property value="%{obj.field}"/>  // With %{}
<s:property value="obj.field"/>     // Without %{}
<s:property value="%{#obj.field}"/> // with %{} and prefixed # 
${obj.field}  // with ${}
// any other types I may have missed... 


推荐答案

那不是JSTL,那是 OGNL 。在Struts标记内,

That's not JSTL, that's OGNL. When inside a Struts tag,

%{} 表示您正在强制对表达式求值。在大多数情况下,它是无用的,因为评估是自动进行的,但是为了保持一致性,可以使用它来清除评估正在进行中的事实。

%{} means you are forcing the evaluation of an expression. Most of the time it's useless, because the evaluation is automatic, but it can be put for consistency, to clear the fact that an evaluation is in progress.

%{foo} 表示您正在访问ValueStack中的foo对象(例如Action属性)。

%{foo} means you are accessing the foo object in the ValueStack (eg. an Action property).

%{#foo} 表示您正在访问在ActionContext中,但不在ValueStack中。

%{#foo} means you are accessing the foo object that is in the ActionContext, but not in the ValueStack.

很好的答案

$ {foo} 是JSP EL(表达语言)。

${foo} is JSP EL (Expression Language).

JSTL是一个不同的库,使用它的专有标签,例如< c:forEach> < c:out /> < c:when> 等。

JSTL is a different library and uses its proprietary tags, like <c:forEach>, <c:out />, <c:when> and so on.

您可以混合使用JSTL和OGNL ,顺便说一句。

在使用Struts2时,通常使用OGNL和Struts标记(但如果使用了JSTL,没有什么会阻止您使用JSTL你要)。使用Spring MVC时,仅使用JSTL。

When using Struts2, you usually use OGNL and Struts tags (but nothing prevent you to use JSTL, if you want). When using Spring MVC, you use JSTL only.

EL在处理JSP时始终可以使用,但是它具有某些缺点,并且需要通过Struts2进行一些调整。

EL can always be used when dealing with JSP, but it has some drawbacks, and needs some tuning with Struts2.

这篇关于Struts 2和带有EL的Spring-打印变量的不同类型是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆