Struts2由2.0.11.1升级到2.5.20引发的问题:Attribute [id] invalid for tag [iterator] according to TLD
1、产生异常:
SEVERE: Servlet.service() for servlet [jsp] threw exception
org.apache.jasper.JasperException: /jsp/admin/rating.jsp (line: [152], column: [8]) Attribute [id] invalid for tag [iterator] according to TLD
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:292)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:115)
at org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1275)
at org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:888)
at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1544)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2389)
at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2441)
at org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:907)
at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1544)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2389)
at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2441)
at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2447)
at org.apache.jasper.compiler.Node$Root.accept(Node.java:470)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2389)
at org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1857)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:224)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:385)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:362)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:346)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:603)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:399)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:712)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:459)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:384)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)
at org.apache.struts2.result.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:169)
at org.apache.struts2.result.StrutsResultSupport.execute(StrutsResultSupport.java:206)
2、问题分析:
/jsp/admin/rating.jsp页面中第152行:
3、产生异常的原因:
在jsp页面中定义了<%@ taglib prefix="s" uri="/struts-tags"%>,表明引入Struts2的标签库。
其中taglib相当于java中的import导入某个库,prefix="s",表明可以通过
在struts2-core-2.5.20.jar下的META-INF下找到struts-tags.tld文件可以知道为什么这样指定uri:
Struts2.5将iterator标签的id属性取消了,使用var来代替。
4、解决办法:
页面第152行: