我正在尝试使用EL来显示字段,但是即使getter方法正确,我仍然会遇到异常。这可能是我正在显示的表格:
<tr>
<td><c:out value="${sessionScope.user.email}"></c:out></td>
<td id="myusername"><c:out value="${sessionScope.user.userName}"></c:out></td>
<td><c:out value="${sessionScope.user.userID}"></c:out></td>
<td><c:out value="${sessionScope.user.cardListSize}"></c:out></td>
<td id="currentrank"><c:out value="${sessionScope.user.rank}"></c:out></td>
<td hidden="true" id="currentpoints"><c:out value="${sessionScope.user.points}"></c:out></td>
</tr>
${sessionScope.user.rank}
和${sessionScope.user.points}
是导致错误的原因,如果我删除了这两个错误,其他所有内容都会正确加载。这是我在转发到此JSP之前设置属性的方法:
UserAccount userAccount = DataDAO.findUser(userName, password);
HttpSession session = request.getSession(true);
session.setAttribute("user",userAccount);
这是UserAccount对象的一部分:
public String getRank(){
return rank;
}
public Integer getPoints(){
return points;
}
这是我从数据库检索信息后创建该对象的地方:
if(password.equals(rightPassword)){
Integer userspoints = user.getInt("points");
String rank = DataAnalyzer.determineRank(userspoints);
UserAccount retrievedUser = new UserAccount(userName,rightPassword,user.getString("firstname"),user.getString("lastname"),user.getString("email"),rank,userspoints,user.getString("avatar"));
Integer userID = user.getInt("USER_ID");
retrievedUser.setUserID(userID.toString());
return retrievedUser;
} else {
return null;
}
如果这些字段之一为null,是否会导致找不到属性?
stacktrace:
说明服务器遇到内部错误,导致服务器无法满足此请求。
例外
org.apache.jasper.JasperException:在第90行处理JSP页面/WEB-INF/QuestionPage.jsp时发生异常
87: 88: 89: 90:$ {sessionScope.user.rank} 91:$ {sessionScope.user.points} 92: 93:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:578) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:401) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:345) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) flashcardshark.servlet.LoginServlet.doPost(未知来源) javax.servlet.http.HttpServlet.service(HttpServlet.java:648) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
根本原因
javax.el.PropertyNotFoundException:在类型上找不到属性“等级” flashcardshark.bean.UserAccount javax.el.BeanELResolver $ BeanProperties.get(BeanELResolver.java:268) javax.el.BeanELResolver $ BeanProperties.access $ 300(BeanELResolver.java:221) javax.el.BeanELResolver.property(BeanELResolver.java:355) javax.el.BeanELResolver.getValue(BeanELResolver.java:95) org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:110) org.apache.el.parser.AstValue.getValue(AstValue.java:169) org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:943) org.apache.jsp.WEB_002dINF.QuestionPage_jsp._jspService(QuestionPage_jsp.java:229) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:401) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:345) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) flashcardshark.servlet.LoginServlet.doPost(未知来源) javax.servlet.http.HttpServlet.service(HttpServlet.java:648) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)