关于EL在JSP内调用RequestScope内置对象报错的问题

先贴出源码

Search.java

public class Search {
    private String dest;
    private String date;

    public void setDest(String e){
        dest = e;
    }

    public void setDate(String d){
        date = d;
    }


    public Result getSearchResult(){
        Result r = SearchDao.SearchInfo(dest, date);
        return r;
    }
}

Search.jsp

<%
	Search s = new Search();
	request.setCharacterEncoding("GBK");
	String dest = request.getParameter("dest");
	String date = request.getParameter("date");
	s.setDate(date);
	s.setDest(dest);
	request.setAttribute("SearchInfo", s);
%>
<html>
<head>
	<title>SearchInfo</title>
</head>
<body>
<p>------------------------------------------</p>
<p>查询信息:</p>
<p>目的地:${requestScope.SearchInfo.dest}</p>
<p>出发日期:${requestScope.SearchInfo.date}</p>
<p>------------------------------------------</p>
<%
	Result result = s.getSearchResult();
	Map[] m = result.getRows();
	for(int i = 0; i<result.getRowCount();i++){
		out.println("<p>航班号:"+m[i].get("id")+"  "+"出发时间:"+m[i].get("tfdate")+"  "+"目的地:"+m[i].get("dest"));
	}
%>
<p>-----查询结束-----</p>
</body>
</html>

今天在做作业的时候想要用EL调用RequestScope内置对象的时候 出现了如下错误

javax.el.PropertyNotFoundException: Property [dest] not readable on type [Bean.Search] 

在CSDN上查到发现是所调用对象没有被设置成public

但是更改属性成public之后仍然出现上述错误 


进一步查询发现:点击打开链接

You have 2 options:

  1. Use boolean instead of Boolean.

  2. Or, rename method isPrimary() to getPrimary()

于是在上述Search类中添加getDate()和getDest() 保留date和dest的private属性

发现可行



按照目前测试出来的结果 EL在调用RequestScope内置类对象中的属性时采用的方法是调用getXXX()函数来实现的 

所以想要实现用EL调用内置类对象的属性时一定要有getXXX()类函数


猜你喜欢

转载自blog.csdn.net/csc1998/article/details/80191319