01 <%@ include file="_pages.jspf"%>
02 <%@ include file="/template/head.jspf"%>
03 <%@ page import="java.util.Properties" %>
04 <%
05 if (request.getParameter("delete")!=null) {
06 application.removeAttribute("votings");
07 }
08 String[] langs=new String[] {"JSP","PHP","ASP","ColdFusion"};
09 Properties votings;
10 Object obj=application.getAttribute("votings") ;
11 if (obj==null) {
12 votings=new Properties();
13 application.setAttribute("votings",votings);
14 } else {
15 votings=(Properties) obj;
16 }
17
18 String choice=request.getParameter("choice");
19 if (choice!=null && !choice.equals("")) {
20 int current=0;
21 try {
22 current=Integer.parseInt(votings.getProperty(choice));
23 } catch (NumberFormatException ne) {
24 // do nothing for current is 0
25 }
26 votings.setProperty(choice,(current+1)+"");
27 }
28 %>
29 <h1>Votingtool</h1>
30 <table>
31 <%
32 int max=0;
33 int[] values=new int[langs.length];
34 for (int i=0;i<langs.length;i++) {
35 String voteAsString=votings.getProperty(langs[i]);
36 if (voteAsString!=null) {
37 try {
38 values[i]=Integer.parseInt(voteAsString);
39 max=Math.max(values[i],max);
40 } catch (NumberFormatException ne){
41 values[i]=0;
42 }
43 } else {
44 values[i]=0;
45 }
46 }
47 for (int i=0;i<langs.length;i++) {
48 int percent=0;
49 if (max!=0) {
50 percent=values[i]*100/max;
51 }
52 %>
53 <tr>
54 <td><a href="<%=request.getRequestURI()+"?choice="+langs[i] %>"><%=langs[i] %></a></td>
55 <td><img src="gfx/blue.gif" width="<%= percent%>" height="5" alt="" border="0"></td>
56 <td><%= values[i] %></td>
57 </tr>
58 <%} %>
59 </table>
60 <br>
61 <a href="<%=request.getRequestURI()+"?delete"%>">l?schen</a>
62 <br>
63 <br>
64
65
66
67
68 <%=votings %>
69 <%@ include file="/template/tail.jspf"%>
|