I'm having a weird error when reloading my index.jsp
page in a java web project.
<%
// index.jsp
// imports
String teams = Init.getTeams();
%>
<!-- default html content -->
<select class="select">
<option value="0" selected="selected">Choose Home Team</option>
<%= teams %>
</select>
<!-- default html content -->
So I'm calling Init.getTeams()
from this java method:
public static String getTeams() {
String s = "";
ArrayList<Team> teams = new ArrayList<Team>();
teams = MySQLConnection.getTeams();
for (Team t : teams) {
s += "<option value='" + t.getId() + "'>" + t.getName() + "</option>";
}
return s;
}
(Connects to a MySQLConnection class that I've written to retrieve the values from the database). And it'll return something like this:
<option value='1'>Royals</option>
<option value='2'>Red Sox</option>
<option value='3'>Athletics</option>
<option value='4'>Tigers</option>
<option value='5'>Rays</option>
<option value='6'>Angels</option>
... and correctly populate the select box. The problem is that when I reload the page, it duplicates the string that is returned and all the <option>
s are duplicated. Why is this happening?
Edit: Probably worth noting I'm running apache tomcat server, and when restarted, it resets and is displayed 1 time the first time the page is brought up, 2 times on the second time, etc. I've also tried to use meta tags to not cache the page, as that's what I suspected was happening - with no luck.