访问会话范围中的对象

时间:2012-05-23 04:30:38

标签: jsp session-variables

我正在构建一个UI模板&因此没有java文件。但是我需要java对象,所以我只在jsp中有类定义。我需要在“results”数组中打印每个对象的gameState属性。如何打印?

此行有问题“$ {sessionScope ['results'] [innerItemNumber] .gameState} [br]”。我不确定语法。

我收到错误“javax.el.PropertyNotFoundException:属性'gameState'在类型java.lang.String上不可读”。

test.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 > 

1 个答案:

答案 0 :(得分:0)

将你的课程从你的某些软件包中移出jsp,一切都会正常工作。别忘了把它公之于众。