JSTL会话查找-关键有句点 [英] JSTL Session Lookup - Key Has Periods

查看:70
本文介绍了JSTL会话查找-关键有句点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一些旧代码,有时在会话中有一个类似于

I am working with some legacy code, and at some point there is a key in the session that is something like

session.setAttribute("com.org.something.Object",someObject);

现在尝试使用jstl在jsp中访问它有点困难,因为如果我像通常那样尝试的话,就会这样做:

Now trying to access this in a jsp using jstl is a bit difficult becuase if I tried it like I normally would I would do:

${sessionScope.com.org.something.Object.someFieldGetter}

我们大多数人都可以想象它会失败,因为会话范围内没有com对象.我也尝试过

As most of us can imagine it will fail because there is no com object in session scope. I also tried

${sessionScope.'com.org.something.Object'.someFieldGetter} 

然后引发了解析错误.

有人知道如何解决这个问题,以便我可以通过jstl正确获得类似于session.getAttribute("com.org.something.Object")的对象吗?

Does anyone know how to resolve this so that I can correctly get the object similar to session.getAttribute("com.org.something.Object") but through jstl?

谢谢.

推荐答案

使用方括号语法.

${sessionScope['com.org.something.Object'].someFieldGetter}应该这样做.

这篇关于JSTL会话查找-关键有句点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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