File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Struts Basic EL question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Basic EL question" Watch "Struts Basic EL question" New topic

Struts Basic EL question

Ramkumar Subburaj
Ranch Hand

Joined: Sep 07, 2007
Posts: 83

I would like to know when to use #, % and %{#name} in struts 2 jsp page


SCJP 1.5, SCWCD 1.4.
Hanging between Web Services and EJB
David Newton

Joined: Sep 29, 2008
Posts: 12617

Use "#" when you're accessing a *named* value stack variable, like #session, or any you've created[1]. use the completel OGNL escape sequence, "%{expr}", when you want to explicitly tell the framework to evaluate the contents, or to just make it clear that you're using OGNL (this is the recommended practice--use it for *every* OGNL expression, even if you don't have to).

[1] This isn't always true as of Struts 2.1.mumble; *sometimes* it's optional. It's always been unclear to me when it's optional, or how to find out when it's optional. That's something I plan to work on.
I agree. Here's the link:
subject: Struts Basic EL question
It's not a secret anymore!