JSP 中无法使用EL表达式 原因

本文探讨了在使用JSP与PagerTagLibrary时遇到的问题:当属性值为变量时出现NumberFormatException错误。通过调整页面配置,设置isELIgnored属性为false,解决了表达式语言(EL)在JSTL标签外部的评估问题。

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

Hello to all from Spain

Well, my problem is:

I use JSP, LE and a tag library called "Pager Tag Library".
I have a .jsp page with this:

<c:set var="varbool" value="false"/>

<pg:pager items="<%= varNumFilas.intValue() %>"
url="consultatit.do"
index="center"
maxPageItems="5"
maxIndexPages="5"
isOffset="${varbool}"
export="offset,currentPageNumber=pageNumber"
scope="request">

This code works well. No problem. But with...

<c:set var="varNumFilas" value="15"/>
<c:set var="maxpages" value="5"/>

<pg:pager items="${varNumFilas}"
url="consultatit.do"
index="center"
maxPageItems="5"
maxIndexPages="${maxpages}"
isOffset="false"
export="offset,currentPageNumber=pageNumber"
scope="request">

I get an error:

java.lang.NumberFormatException: For input string: "${varNumFilas}"
java.lang.NumberFormatException.forInputString(Unknown Source)
java.lang.Integer.parseInt(Unknown Source)
java.lang.Integer.valueOf(Unknown Source)
org.apache.jasper.compiler.JspUtil.coerceToInt(JspUtil.java:796)
...

Always, with any variable...

That is to say, when the required value of the attribute is numeric there is an error, and when the required value is not numeric (an String) there is not an error... ?Why?

Thanks to all


_______________
solve:

So the question is, what server/JSP spec are you using?

If you are using Tomcat 5.x or JSP2.0 spec, then you get EL evaluated outide of JSTL tags by adding:


<%@ page isELIgnored="false" %>


At the the top of the page.

If you are using an older version of Tomcat, or a server that does not support JSP 2.0, then you will have to re-write the Page Tags to be able to translate EL for you, or not use EL...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值