带OGNL的Struts 2动态消息 [英] Struts 2 Dynamic message with OGNL

查看:49
本文介绍了带OGNL的Struts 2动态消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Struts 2项目中,请考虑以下消息资源的关键点:

In a Struts 2 project, consider below key in message resources:

export.filename.accountsummary=customer ${export}

动作已将export提交给setter和getter. 如果调用getText("export.filename.accountsummary"),struts将自动调用getExport(),并用正确的值填充. (我认为Struts也使用OGNL查找支持${}的资源消息)这是正确的吗?!

The action has export filed with setter and getter. If you call the getText("export.filename.accountsummary") struts will automatically call the getExport() and fill it with correct value. (I think that struts use OGNL too lookup the resource messages that are endorse with ${}) Is this correct ?!

我尝试使用customer ${#sessionScope.CurrentUser.userName}预期,struts使用此OGNL表达式,但是没有用.

I try to use customer ${#sessionScope.CurrentUser.userName} an expected that struts use this OGNL expression but it did not worked.

推荐答案

看起来变量sessionScope在上下文中不可用(如果您未手动将其放置).不要将其与JSP会话作用域变量搞混(语法类似于在JSP for EL中使用的语法,但是Struts2在那里不使用JSP EL引擎),OGNL表达式中的所有内容均针对OGNL上下文进行了评估.您可以在消息中使用${}语法,Struts会为OGNL表达式解析其值,并且此语法定义了表达式的范围,该范围在删除${}之后进行评估.

Looks like the variable sessionScope is not available in the context (if you didn't put it manually). Don't mess it up with JSP session scope variable (the syntax is similar that is used in JSP for EL, but Struts2 doesn't use JSP EL engine there), everything in OGNL expression evaluated against the OGNL context. You can use ${} syntax in messages, Struts parses its value for OGNL expression, and this syntax defines a scope of the expression, which is evaluated after removing ${}.

这篇关于带OGNL的Struts 2动态消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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