这是我的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调用一个函数,如果我调用一个非参数化函数,那么代码工作正常,但调用参数化函数时出现问题
答案 0 :(得分:1)
您需要更改方法名称:
<c:forEach items="${sessionScope.shp_prdct.getname(asd)}" var="product">
The name is ${product.b}
</c:forEach>
如果使用参数调用方法,则需要使用完整的方法名称。