AK2
AK2

Reputation: 111

Unable to call a parameterized function using JSTL

This is my JSP page:

<!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>

This is my Java Class:

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;
     }
      }

The error I am facing is:

exception

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

javax.el.MethodNotFoundException: Method name not found

I don't know what I am doing wrong here.I am trying to call a function through JSTL if i call an unparameterized function then the code works fine but the problem occurs while calling parameterized function

Upvotes: 1

Views: 1049

Answers (1)

nfechner
nfechner

Reputation: 17545

You need to change the method name:

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

If you call a method with parameters, you need to use the full method name.

Upvotes: 1

Related Questions