0

尝试使用 jstl 在 vi​​ew.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)
4

1 回答 1

3

您正在尝试使用value属性,该属性不是<c:forEach>标签的有效属性。也许您打算使用items

<c:forEach begin="1" end= "${ no }" step="1" varStatus="loopCounter"
           items="${coursesummaries}" var="coursesummary">

有关有效属性的列表,请参阅<c:forEach>Oracle Doc

除此之外,鉴于您正在迭代集合,我并不真正理解您使用begin,end和, 属性的意图。step你甚至没有使用它们。而且你真的不需要他们恕我直言。

于 2013-08-09T22:09:47.347 回答