对于类型PageContextImpl,未定义方法proprietaryEvaluate(String,Class <string>,PageContext,null)

时间:2016-03-03 06:17:43

标签: jsp tomcat jstl

这是我第一次使用java servlets和JSP。我一直在拼命地尝试从java servlet向JSP页面发送一个列表......没有运气.. :(

我知道错误必须与我在jsp页面中读取数据的方式有关,但在线查看了很多样本​​后,我找不到问题所在。

这是我的servlet和jsp代码

任何建议都将不胜感激

   public class data {

        private String url_hb;
        private String brand_hb;
        private String descr_hb;
        private String dist_hb;
        private String partno_hb;
        private String price_hb;

        public void set_url(String url_hb) {
            this.url_hb = url_hb;
        }

        public void set_brand(String brand_hb) {
            this.brand_hb = brand_hb;
        }

        public void set_descr(String descr_hb) {
            this.descr_hb = descr_hb;
        }

        public void set_dist(String dist_hb) {
            this.dist_hb = dist_hb;
        }

        public void set_partno(String partno_hb) {
            this.partno_hb = partno_hb;
        }

        public void set_price(String price_hb) {
            this.price_hb = price_hb;
        }

        //
        public String get_url() {
            return url_hb;
        }

        public String get_brand() {
            return brand_hb;
        }

        public String get_descr() {
            return descr_hb;
        }

        public String get_dist() {
            return dist_hb;
        }

        public String get_partno() {
            return partno_hb;
        }

        public String get_price() {
            return price_hb;
        }

    }

servlet

 List<data> list = new ArrayList<data>();
            data row0 = new data();
            row0.set_url("testurl");
            row0.set_brand("my brand");
            row0.set_descr("my des");
            row0.set_dist("my dis");
            row0.set_partno("det12321");
            row0.set_price("50000");
            row0.set_url("www.com");       

            list.add(row0);

            ServletContext sc = getServletContext();
            RequestDispatcher rd = sc.getRequestDispatcher("/results.jsp");
            request.setAttribute("list", list);
            rd.forward(request, response);

JSP

 <c:forEach items="${list}" var="r">
                <tr>      
                    <td>${record.price_hb}</td>
                </tr>
 </c:forEach>

我的错误:

org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 63 in the jsp file: /results.jsp
The method proprietaryEvaluate(String, Class<String>, PageContext, null) is undefined for the type PageContextImpl
60:             
61:             <c:forEach items="${list}" var="r">
62:                 <tr>      
63:                     <td>${record.price_hb}</td>
64:                 </tr>
65:             </c:forEach>
66:            

1 个答案:

答案 0 :(得分:0)

将您的变体从r更改为record,然后我想您的代码就会运行。因为此taglib库将从object获取list并将其放入var ="record"所以,使用${record.price_hb}访问您的每个结果

<c:forEach items="${requestScope.list}" var="record">
                    <tr>      
                        <td>${record.price_hb}</td>
                    </tr>
     </c:forEach>