I am working on a sports-betting website. I have a program that fetches sports data and writes/updates a MySQL db. This program stays running on my local PC, where the DB is also located.
In order to retrieve the data, the client (the web browser) creates a new "bean" object. The bean's constructor is to populate some HashMaps with values queried from the DB. Then, the JSP iterates through the bean's HashMaps and displays the content. Here is what the code looks like:
<%
Bean m = new Bean();
%>
<table style="width: 100%">
<tr>
<th colspan="2" align="center">NBA</th>
</tr>
</table>
<% //Iterates through the NBA hashmap
Iterator itrNba = m.getNbaM().entrySet().iterator();
for (Map.Entry<Integer, Match> entry : m.getNbaM().entrySet()) {
Match value = entry.getValue();
%>
<div class="bs-example"> // Creates a table row for every Match object in the hashmap, and outputs its values
<table>
<col width="100">
<col width="20">
<col width="100">
<tr>
<td align="left"><%=value.getTeam0Name()%></td>
<%
if (value.getStatus() != 0) {
%>
<td align="center"><%=value.getTeam0Score()%></td>
<td align="right" rowspan="2"><%=value.getQuarter()%></td>
<%
} else {
%>
<td align="center"></td>
<td align="right" rowspan="2"><%=value.getQuarter()%></td>
<%
}
%>
</tr>
<tr>
<td align="left"><%=value.getTeam1Name()%></td>
<%
if (value.getStatus() != 0) {
%>
<td align="center"><%=value.getTeam1Score()%></td>
<%
}
%>
</table>
</div>
<br>
<%
}
%>
However, I haven't found a simple way to allow my values to refresh. My really simple temporary fix was to just refresh the whole page every X seconds, and then scroll down to where the user previously was viewing. A new bean is created, causing it to read from the DB again. However, this is an approach that is beyond ugly.
Is there a simple way for just the values to refresh? I realize that I may have to look into jQuery and servlets etc, which I am willing to do. However, I would like to stay away from JSON, JS, and lots of client side scripting. Id prefer to stick with JSP or a servlet which has a doPost that prints out html code, but how can I make this loop periodically?
Thanks.