<%@ page language="java" import="java.util.*" %> Stem <% List ips = (List)application.getAttribute("ips"); if(ips==null) { ips = new ArrayList(); application.setAttribute("ips", ips); } Map votes = (Map)application.getAttribute("votes"); if(votes==null) { votes = new HashMap(); application.setAttribute("votes", votes); votes.put("red", new Integer(0)); votes.put("green", new Integer(0)); votes.put("blue", new Integer(0)); } String vote = request.getParameter("stemme"); if(vote!=null) { String ip = request.getRemoteAddr(); if(ips.contains(ip)) { %> <%=ip%> har allerede stemt engang ! <% } else { Integer oldcount = (Integer)votes.get(vote); Integer newcount = new Integer(oldcount.intValue() + 1); votes.put(vote, newcount); ips.add(ip); } } %>

Hvad er din yndlings farve

Rød
Grøn
Blå

Afstemnings resultat

<% Iterator it = votes.keySet().iterator(); while(it.hasNext()) { String color = (String)it.next(); Integer count = (Integer)votes.get(color); %> <% } %>
<%=color%><%=count%>