使用JSTL标记转义JSP EL(点字符) [英] Escape JSP EL using JSTL tags (dot character)

查看:118
本文介绍了使用JSTL标记转义JSP EL(点字符)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

某些框架(Spring,Tomcat本身)添加了默认情况下不能在EL表达式中使用的servlet请求属性.一个例子是

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

所以,要使用我通常使用的JSTL来获取价值

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

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

但是这不起作用,因为EL解析器期望javax是对象A的键,而servlet是该对象的属性(依此类推).

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?

我尝试使用

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

但是这也不起作用,并从EL解析器中引发了一个错误.

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']}" />

这也不起作用.

有什么想法吗?

推荐答案

如果您知道该属性的范围,则可以从适当的隐式对象(例如,

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']}

我不确定是否有隐式对象以{xxx}的方式检查所有范围.

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

这篇关于使用JSTL标记转义JSP EL(点字符)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆