当前收到一个错误消息,表明我的bean中的bankOffer属性无法找到。.
来自我的game.jsp文件,如下所示:
<%@page import="game.Briefcase"%>
<jsp:useBean id="game" class="game.Game" scope="session" />
<%
// If the 'open' parameter is received, it is converted to
// an integer and passed to the method setOpen. The value given
// is the corresponding index for the ArrayList Object.
if (request.getParameter("open") != null) {
game.caseOpen(Integer.parseInt(request.getParameter("open")));
}
// If the 'restart' parameter is given, then the restart method
// is invoked on the game bean.
if (request.getParameter("restart") != null) {
game.newgame();
}
// If the deal parameter is given, then it converts it to a Boolean
// value and performs a conditional test. If the parameter is true,
// then the deal has been made so the page is forwarded to the deal.jsp.
// Otherwise, the gameRound() is incremented cause it is NO DEAL!.
if (request.getParameter("deal") != null) {
if (Boolean.parseBoolean(request.getParameter("deal"))) {
game.setDeal(true);
} else {
game.nextround();
}
}
// If there is a Bank Offer, it will display the amount offered with
// two buttons to either accept or refuse.
if (!game.getDeal()) {
if (game.offerTime()) {%>
<div id="bank_offer">
<div id="bank_offer_title"></div>
<div id="deal_button" onclick="deal(true)"></div>
<div id="bank_offer_text">
<div id="bank_offer_amount">$<jsp:getProperty name="game" property="bankOffer" /></div>
<div id="bank_offer_message">Highest amount left: $<jsp:getProperty name="game" property="highestAmount" /></div>
</div>
<div id="nodeal_button" onclick="deal(false)"></div>
</div>
<%
// Otherwise, the Briefcases will be displayed along with a game message
// above the cases.
} else {
%>
<div id="game_message">
<div id="game_round">
<% if (game.getRound() > 0) { %>
Round: <jsp:getProperty name="game" property="round" />
<% } %>
</div>
<div id="game_text">
<jsp:getProperty name="game" property="message" />
</div>
</div>
<div id="cases">
<%
int index = 0;
// Iterates For Each Briefcase
for (Briefcase briefcase : game.getcases()) {
// If the Briefcase is not opened, then it is displayed as closed with the
// number assigned. Otherwise, if the Briefcase is opened then it is displayed
// as open with the amount value inside.
if (!briefcase.isOpened()) {
// If the Briefcase is the chosen case, then it will be displayed with
// 'Your Briefcase' on the image. The Briefcase's once pressed invokes
// a JavaScript function called openBriefcase() which passes the
// index. The function then invokes an Ajax call to the same .jsp which the
// html is then placed into the game container on the main index.jsp.
%>
<div onclick="openBriefcase(<%=index%>)" class="<%=(((game.getChosen() != null)
&& game.getChosen().equals(briefcase)) ? "briefcase_chosen" : "briefcase_closed")%>">
<div class="briefcase_number"><%=briefcase.getNumber()%></div></div>
<%} else {
// Once the case is opened it gets displayed with an open background
// with the case amount centered.
%>
<div class="briefcase_open">
<div class="briefcase_amount">$<%=briefcase.getValue()%></div>
</div>
<%}
index++;
}%>
</div>
<%
}
} else { %>
<div id="deal_message">
Deal $<jsp:getProperty name="game" property="bankOffer" />
</div>
<%
}
%>
Hmu链接所需的任何其他文件。上一个文件是索引jsp,可以很好地加载我的其他动态内容,但不加载game.jsp。
我们将不胜感激,这是我第一次必须以任何广泛的方式使用jsp,所以现在我很茫然。
答案 0 :(得分:0)
确保类game.Game
具有名为bankOffer
的bean属性(而不仅仅是字段)。 Java bean属性是由其getter和setter定义的,因此,要使bankOffer
为属性,类game.Game
必须包含公共方法getBankOffer
(如果包含{布尔属性)和isBankOffer
。