Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Struts 2 "%" sign and '#" sign in OGNL

Tags:

java

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.

thanks

like image 356
acoolme Avatar asked Oct 19 '11 16:10

acoolme


1 Answers

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.

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 Docs
  • S2-specific OGNL Docs
  • OGNL reference docs
like image 59
Dave Newton Avatar answered Oct 22 '22 21:10

Dave Newton