Escape JSP EL using JSTL tags (dot character)
Asked Answered
L

1

7

Some frameworks (Spring, Tomcat itself) add servlet request attributes that cannot be used within an EL expression by default. An example would be

javax.servlet.forward.context_path = /myWebapp

So, to get the value using JSTL I'd normally use

<c:out value="${javax.servlet.forward.context_path}" />

However that's not working because the EL parser expects javaxto be the key of object A and servlet to be a property of that object (and so on).

So my question is: How do I escape the dot character?

I've tried using

<c:out value="${javax\.servlet\.forward\.context_path}" />

but that's not working either and raises an error from the EL parser.

I know that when dealing with maps I can use something like

<c:out value="${aMap['key.from.map.with.dots']}" />

but thats not working with a first level object from the request, since I've also tried using

<c:out value="${['javax.servlet.forward.context_path']}" />

which is not working either.

Any ideas?

Luanaluanda answered 15/7, 2011 at 9:38 Comment(0)
T
9

if you know the scope of the attribute, then you can fetch it from the appropriate implicit object, e.g.

${requestScope['javax.servlet.forward.context_path']}

I'm not sure if there's an implicit object that checks all scopes in the way that {xxx} does, though.

Taam answered 15/7, 2011 at 12:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.