Struts 2“%"签名和“#"登录 OGNL

2022-01-16 00:00:00 java struts2 ognl

谁能告诉我如何在 STRUTS2 OGNL 中使用%"和#"符号?我用谷歌搜索,但找不到任何有价值的信息.或者给我一个文档链接.

Anybody can tell me how to use "%" and "#" sign in STRUTS2 OGNL? I google around, but can't find any valuable info about this.Or give me a link of documentation of this.

谢谢

推荐答案

% 字符强制 OGNL 评估,所以 <s:property name="%{foo}"/> 将在堆栈中查询 foo 属性.它并不总是必需的(实际上很少),但为了清晰起见,它更容易始终如一地使用.

The % character forces OGNL evaluation, so <s:property name="%{foo}"/> will query the stack for a foo property. It's not always required (rarely, in fact), but it's easier to use it consistently for clarity.

# 字符访问 named 值堆栈上下文变量,例如,您曾经需要它来访问使用 <s 创建的变量:设置>标签.您需要它来访问诸如会话变量之类的东西,例如 <s:property name="#session.user.name"/>.

The # character accesses a named value stack context variable, for example, you used to need it to access a variable created using the <s:set> tag. You need it to access things like a session variable, like <s:property name="#session.user.name"/>.

  • S2 OGNL 文档
  • 特定于 S2 的 OGNL 文档
  • OGNL 参考文档

相关文章