struts标签和el混用问题

本文详细介绍了在使用Struts2.1.8时遇到EL表达式不支持的问题,以及如何通过修改代码和配置解决该问题的过程。重点在于将EL表达式转换为OGNL表达式,并在struts.xml中启用OGNL允许静态方法访问。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天做项目遇到的问题,找了半天搞定了。

 <s:iterator var="customer" value="custList">

  <s:if test="${customer.custLevel==1}">vip 客户

</s:if>

</s:iterator>

这种写法在struts2.1.8中不支持el表达式,报一下异常:According to TLD or attribute directive in tag file, attribute test does not accept any expressions;;

然后改成

 <s:iterator var="customer" value="custList">

  <s:if test="%{#customer.custLevel==1}">vip 客户

</s:if>

</s:iterator>

这样就ok .. 如果判读的类型是字符串,要写成 " " ,不能用‘ ’ 

这样写struts2 需要用到ongl...struts2默认ongl false;

struts.xml 中添加此配置:

<constant name="struts.ognl.allowStaticMethodAccess" value="true" /> 

。。

问题解决了。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值