el java常量,通过常量在JSP EL中获取变量不起作用

"本文讨论了在使用GlassFish4.1webprofile中遇到的EL3.0表达式问题。作者在JSP中尝试通过request.setAttribute设置常量,并在JSP页面中通过${requestScope}
摘要由CSDN通过智能技术生成

I use GlassFish 4.1 web profile which as I understand uses EL 3.0. I did everything as was explained here - https://stackoverflow.com/a/3735006/5057736 however my implementation of this solution doesn't work.

This is my constant class

public class CommonKeys {

public static final String TITLE = "SOME_KEY";

}

This is how I set attribute:

request.setAttribute(CommonKeys.TITLE, "TEST");

This is my jsp:

Method 1:
Method 2:${requestScope[CommmonKeys.TITLE]}
Method 3:${requestScope["SOME_KEY"]}

This is the output I get

Method 1:TEST

Method 2:

Method 3:TEST

Why does Method 2 not work?

解决方案

Method 2:${requestScope[TITLE]}

Change your code as per above, should be working fine. It works for me.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值