簡體   English   中英

無法使用JSTL調用參數化函數

[英]Unable to call a parameterized function using JSTL

這是我的JSP頁面:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
 </head>
 <body>
   <jsp:useBean id="x" class="beans.JSTL_demo_class">
       <jsp:setProperty name="x" property="b" value="PRASHANT"/>
    </jsp:useBean>

     <%
   session.setAttribute("shp_prdct", x);
   %>
 <c:set var="asd" value="John"></c:set>
 <c:forEach items="${sessionScope.shp_prdct.name(asd)}" var="product"> 
    The name is  ${product.b}
 </c:forEach> 
    name is ${asd}
  </body>
 </html>

這是我的Java類:

package beans;

import java.util.List;


    public class JSTL_demo_class {


    public int a;
    public String b;
    public String c;
    public int d;
    public String e;

    public int getA() {
        return a;
    }

    public void setA(int a) {
        this.a = a;
    }

    public String getB() {
        return b;
    }

    public void setB(String b) {
        this.b = b;
        System.out.println("The parameter is "+this.b);
    }

    public String getC() {
        return c;
    }

    public void setC(String c) {
        this.c = c;
    }

    public int getD() {
        return d;
    }

    public void setD(int d) {
        this.d = d;
    }

    public String getE() {
        return e;
    }

    public void setE(String e) {
        this.e = e;
    }


    public List getname(String name1)
    {
        java.util.ArrayList al=new java.util.ArrayList();
        JSTL_demo_class d=new JSTL_demo_class();
        d.setB(name1);
        al.add(d);
        return al;
     }
      }

我面臨的錯誤是:

exception

org.apache.jasper.JasperException: javax.el.MethodNotFoundException: Method name not found
root cause

javax.el.MethodNotFoundException: Method name not found

我不知道我在這里做錯了什么。我正在嘗試通過JSTL調用一個函數,如果我調用了一個未參數化的函數,那么代碼可以正常工作,但是在調用參數化函數時會出現問題

您需要更改方法名稱:

<c:forEach items="${sessionScope.shp_prdct.getname(asd)}" var="product"> 
    The name is  ${product.b}
</c:forEach>

如果使用參數調用方法,則需要使用完整的方法名稱。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM