java - accessing static field of class from jsp -
in web app, servlet printing html below
protected void doget( httpservletrequest request, httpservletresponse response ) throws servletexception, ioexception { response.setcontenttype( "text/html" ); printwriter pw = response.getwriter(); pw.println( "<html><head></head><body>" ); printbody( pw ); pw.println( "</body></html>" ); }
where printbody
is
private void printbody( printwriter pw ) { pw.println( "<form id='pool' method='post'>" ); pw.println( "<table>" ); pw.println( "<tr><th>home team</th><th>away team</th><th>tiebreaker?</th></tr>" ); bettingpoolgame[] games = bettingpool.getgames(); (int = 0; < games.length; i++) { pw.println( "<tr><td><input name='home" + + "' value='" + games[i].gethometeam() + "'></td>" ); pw.println( "<td><input name='away" + + "' value='" + games[i].getawayteam() + "'></td>" ); pw.print( "<td><input type='radio' name='tiebreaker' value='" + + "'" ); if (i == bettingpool.gettiebreakerindex()) pw.print( " checked" ); pw.println( " /></td></tr>" ); } pw.println( "</table>" ); if (bettingpool.iseditable()) { pw.println( "<input type='submit' name='save' value='save' />" ); pw.println( "<input type='submit' name='save' value='open pool' />" ); } pw.println( "</form>" ); }
the bettingpool
class has static fields , accessors
public class bettingpool { private static int tiebreakerindex; ... public static int gettiebreakerindex() { return tiebreakerindex; } ... }
i use jsp page instead of printbody() method , tried this
<body> <jsp:usebean id="bettingpool" class="dyna.pool.bettingpool"></jsp:usebean> <h3>pooleditorform</h3> <form id='pool' method='post'> <table> <tr><th>home team</th><th>away team</th><th>tiebreaker?</th></tr> <c:foreach items="${games}" var="x" varstatus="status"> <tr><td><input name='home${status.index}' value='${x._hometeam}' ></td> <td><input name='away${status.index }' value='${x._awayteam}'></td> <td><input type='radio' name='tiebreaker' value='${status.index}'/></td></tr> <c:if test="${status.index == bettingpool.tiebreakerindex}"> checked </c:if> </c:foreach> </table> <input type='submit' name='save' value='save'/> <input type='submit' name='save' value='open pool' /> </form> </body>
however,i getting error like
javax.el.propertynotfoundexception
: property 'tiebreakerindex' not found on typedyna.pool.bettingpool
any idea how can access static field of class jsp page? thanks
mark.
just remove static
method , in other word make non static getter method .because jstl el looks standard accessors method.
Comments
Post a Comment