使用 OGNL 从 Map返回数据
使用Struts 2.1.6、xwork 2.1.2和ognl 2.6.11 在我的 struts 操作中,我有一个 Map,我正在使用 OGNL 从中获取元素。如果我用来获取的键在映射中不存在,那么 OGNL 返回一个空对象数组,OGNL 将该数组转换为字符串,然后我得到对象引用 java.lang.Object@6.... 这发生在几个例子中放置并且似乎是具有指定为对象的泛型值的地图。这不是我能改变的。 我已经追踪这个问题有一段时间了,但是当我最终深入 OGNL 代码的内部时,我并没有看到隧道尽头的曙光。目前,我将进行一个丑陋的黑客检查字符串返回,看看它是否以“java.lang.Object@”开头,如果是,则返回一个空字符串。我不喜欢这个解决方案,但这就是时间允许的。 有人遇到过类似的问题吗?
另外,OpenSymphony 去哪儿了?他们网站的更新似乎已经枯竭,用户论坛表示他们将在 2009 年 11 月 12 日之前转换为 Google 网上论坛
Using Struts 2.1.6, xwork 2.1.2 and ognl 2.6.11
In my struts action I have a Map that I am fetching elements from using OGNL. If the key I am using to fetch with does not exist in the map then OGNL returns an empty object array, that OGNL converts to a string and I get the object reference java.lang.Object@6.... This occurs in several places and seems to be the the map having the value generic specified as an Object. This is not something I can change.
I have traced the problem for a while, but when I ended up deep into the guts of the OGNL code and I did not see a light at the end of the tunnel. Currently I am going to go with an ugly hack of checking the string return to see if it starts with "java.lang.Object@" and if so return an empty string. I don't like the solution but thats what time permits.
Has anyone encountered a similar problem?
Also, where did OpenSymphony go? updates to their webiste appear to have dried up, the user forums say they are being converted to Google Groups no later than Nov-12-09
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是空值的问题:如果值为空,默认行为是使用默认构造函数创建一个值。由于映射的值类型是 Object,因此会在 null 所在的位置创建新对象。
为了停止此行为:
@CreateIfNull( value = false )
mapName_CreateIfNull=false
。This is a problem with null values: if value is null, default behavior is to create a value using default constructor. Since the value type of your map is Object, new Objects are created where null is.
In order to stop this behavior:
@CreateIfNull( value = false )
mapName_CreateIfNull=false
in classname-convertion.properties file.