1

I am trying to use s:url and the value contains a property. And it's not working.

<s:url value='/js/myJS-<s:property value="locale"/>.js'/>

Expected output:

....../contextPath/js/myJS-en_US.js
Roman C
  • 49,761
  • 33
  • 66
  • 176
Drogba
  • 4,186
  • 4
  • 23
  • 31

1 Answers1

5

Nesting JSP tags like that is illegal.

Use normal JSP EL (assuming you're on a container supporting it):

<s:url value="/js/myJS-${locale}.js"/>

If you're not running a container that supports JSP EL (ew), use OGNL:

<s:url value="/js/myJS-%{locale}.js"/>

It's arguable this is the preferred mechanism since OGNL is S2's default EL.


When reporting something as "not working", you should also include what error(s) you get, for example, in this case, the JSP would never compile.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • Sorry, I am quite new to struts2. I have just try your code and the locale is not evaluated. What should I do/include to support EL in my jsp? – Drogba Jan 25 '13 at 02:25
  • @Drogba As long as you're using any recent servlet container and have the web.xml set to 2.5+ (IIRC) it should work w/o any issues. – Dave Newton Jan 25 '13 at 02:29
  • the web.xml version is 2.4. Any alternative? – Drogba Jan 25 '13 at 02:45
  • 1
    @Drogba Switch to 2.5. It's a container issue, not a web.xml issue. Or use OGNL, S2's native EL: ``, which might be the preferable solution anyway. – Dave Newton Jan 25 '13 at 02:47
  • Thanks so much. it works like a charm. You have mentioned that container issue, i am a bit confused about this. The difference between "%" and "$" is related to jboss? web.xml? struts lib? tag? Could you explain a bit more? – Drogba Jan 25 '13 at 03:07
  • @Drogba http://stackoverflow.com/questions/9421567/whats-the-difference-between-and/9421667#9421667 – Dave Newton Jan 25 '13 at 03:16