尝试使用 jstl 在 view.jsp 中填充表以访问存储在 ViewServlet 的请求对象中的对象列表时,出现以下错误:
/WEB-INF/jsp/admin/view.jsp (line: 34, column: 16) Attribute value invalid for tag forEach according to TLD
谁能告诉我如何修复我的代码,以便我正确地填充表格而不会出错?
以下是 view.jsp 的相关部分:
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<table>
<!-- here should go some titles... -->
<tr>
<th>Type</th>
<th>Number</th>
<th>id</th>
</tr>
<c:forEach begin="1" end= "${ no }" step="1" varStatus="loopCounter"
value="${coursesummaries}" var="coursesummary">
<tr>
<td>
<c:out value="${coursesummary.coursetype}" />
</td>
<td>
<c:out value="${coursesummary.numunits}" />
</td>
<td>
<c:out value="${coursesummary.id}" />
</td>
</tr>
</c:forEach>
</table>
以下是 ViewServlet.java 的相关部分:
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String idString = req.getParameter("id");
Long id = new Long(idString);
List<CourseSummary> coursesummaries = new CourseSummaryDAO().findAll(id);
req.setAttribute("coursesummaries", coursesummaries);
jsp.forward(req, resp);
}
这是整个堆栈跟踪:
org.apache.jasper.JasperException: /WEB-INF/jsp/admin/view.jsp (line: 34, column: 16) Attribute value invalid for tag forEach according to TLD
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:443)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:237)
org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1265)
org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:875)
org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1539)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2434)
org.apache.jasper.compiler.Node$Root.accept(Node.java:475)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1798)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:217)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:373)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
myapp.ViewServlet.doGet(ViewSchoolServlet.java:39)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
myapp.SecurityFilter.doFilter(SecurityFilter.java:56)