3

I'm getting a little bit frustrated since I can't find out which variables I can access with the ${...} syntax in a Struts tag, placed in a JSP page.

As an example I've got the following code:

<c:set target="${status.menue}" property="activeMenuePath" value="whatever" />

Where does the object "status.menue" have to be defined in order to can be accessed with a dollar sign and braces. Is it defined in another struts tile or in the form?

  • 2
    Question saved my life as you mentioned 'dollar' and 'braces' which makes it searchable with google as google does not let you search for '${'... – fgysin Nov 01 '12 at 10:19

1 Answers1

5

It should be placed in any of the page, request, session or application scopes using respectively JspContext#setAttribute(), ServletRequest#setAttribute(), HttpSession#setAttribute() or ServletContext#setAttribute(). You normally do that either directly or indirectly inside a Servlet. MVC frameworks do that indirectly, usually configureable by giving the model object a "request", "session" or "application" scope.

The Expression Language (EL) will access them using JspContext#findAttribute().

This all is by the way unrelated to Struts. It's just a legacy MVC framework which is built on top of the JSP/Servlet API. The <c:set> is not a Struts tag as well, it's a JSTL tag.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • This answer was important for me since I wanted to know which different contexts there are and how to use them. Thank you. – Niklas Rosencrantz May 22 '12 at 09:19
  • I am not sure if it is required but I had to add `<%@ page isELIgnored="false"%>` to my jsp for these expressions to work – Colin D Mar 19 '18 at 01:23