我正在构建一个 UI 模板,因此没有 java 文件。但是我需要 java 对象,所以我的 jsp 中只有类定义。我需要在“结果”数组中打印每个对象的 gameState 属性。怎么打印?
这行“${sessionScope['results'][innerItemNumber].gameState}[br]”有问题。我不确定语法。
我收到错误“javax.el.PropertyNotFoundException: Property 'gameState' not readable on type java.lang.String”。
测试.jsp:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
class Result {
String gameState;
String result;
String optional;
public Result(String gameState, String result, String optional) {
this.gameState = gameState;
this.result = result;
this.optional = optional;
}....
.....// Getters & setters
}
%>
<% java.util.ArrayList<Result> results = new java.util.ArrayList<Result>();
results.add(new Result("Kick off", "14:00", ""));
results.add(new Result("1st Half", "2-2", ""));
results.add(new Result("1st Half", "2-1", ""));
results.add(new Result("Peanalties", "3-6", "(1-1 FT)"));
results.add(new Result("2nd Half", "2-0", ""));
%>
....
.....
<c:forEach items="0,1,2,3,4,5,6" var="innerItemNumber">
<cell class="vertical-align-middle" width="33%" text-align="center">
${sessionScope['results'][innerItemNumber].gameState}[br] ?????????
</cell>
</c:forEach >