Java – use JSTL tag to escape JSP el (dot character)

Some frameworks (spring, Tomcat itself) add servlet request attributes that cannot be used in El expressions by default One example is

javax.servlet.forward.context_path = /myWebapp

So, in order to get values using JSTL, I usually use

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

But this is useless because the El parser expects javaxto to be the key to object a, and servlet is the attribute of the object (and so on)

So my question is: how to escape some roles?

I tried it

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

But it doesn't work and raises an error from the El parser

I know I can use something similar when working with maps

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

But I didn't use the first level object in the request because I also tried to use it

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

It doesn't work either

Any ideas?

Solution

If you know the scope of the property, you can get it from the appropriate implicit object, such as

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

I'm not sure if there is an implicit object that checks all ranges in the way of {XXX}

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>