c:forEach NumberFormatException for start value in start value

时间:2014-01-02 17:31:49

标签: jstl el

我将JSTL从1.1.x升级到1.2,当我尝试使用以下代码编译jsp时,我现在正在获得NFE:

<c:set var="bidCount" value="1"/>
<c:forEach var="i" begin="${bidCount}" end="${totalCount}">
    ...
</c:forEach>

即使我100%确定var bidCount包含一个整数,我仍然会得到一个NFE。

堆栈追踪:

java.lang.NumberFormatException: For input string: "${bidCount}"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:449)
at java.lang.Integer.valueOf(Integer.java:554)
at org.apache.jasper.compiler.JspUtil.coerceToInt(JspUtil.java:752)
at org.apache.jasper.compiler.Generator$GenerateVisitor.convertString(Generator.java:2948)
at org.apache.jasper.compiler.Generator$GenerateVisitor.evaluateAttribute(Generator.java:2751)
at org.apache.jasper.compiler.Generator$GenerateVisitor.generateSetters(Generator.java:2857)
at org.apache.jasper.compiler.Generator$GenerateVisitor.generateCustomStart(Generator.java:2176)
at org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1685)
at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1441)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
at org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
at org.apache.jasper.compiler.Generator.generate(Generator.java:3304)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
at org.apache.jasper.JspC.processFile(JspC.java:986)
at org.apache.jasper.JspC.execute(JspC.java:1135)
at org.codehaus.mojo.jspc.AbstractJspcMojo.execute(AbstractJspcMojo.java:248)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
at org.codehaus.classworlds.Launcher.main(Launcher.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

我正在使用JSTL 1.2。这是我的web.xml的开头:

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">

这是我的pom.xml中的依赖项:

<dependency>
     <groupId>javax.servlet</groupId>
     <artifactId>jstl</artifactId>
     <version>1.2</version>
</dependency>

哦,还有,编辑添加,我确认jstl jar在我的war文件中:

 $ jar -tvf mexp-webapp-3.0-SNAPSHOT.war | grep jstl
414240 Fri Dec 20 12:12:38 EST 2013 WEB-INF/lib/jstl-1.2.jar

1 个答案:

答案 0 :(得分:0)

检查您是否有正确的声明

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>