?? vote.jsp
字號:
<%@page
language="java"
contentType="text/html;charset=GBK"
import="java.util.*,
java.text.*"
%>
<%@include file="/checksession.jsp"%>
<%@include file="/config.jsp"%>
<%@include file="/jdbc_database.jsp"%>
<%
String username="";
String userid="";
String tempstr="";
String sqlstr="";
String title="查看投票項目";
String statestr="歡迎您參加投票調查!";
String voteid="";
String id="";
try
{
username=session.getValue("session_username").toString();
userid=session.getValue("session_userid").toString();
if(request.getParameter("id")==null)
{
response.sendRedirect("voteadmin.jsp?statestr=4");
return;
}
id=request.getParameter("id");
if(request.getParameter("voteid")!=null)
{
voteid=request.getParameter("voteid");
String voted="";
if(session.getValue("session_voted")!=null)
{
boolean votedid=false;
StringTokenizer votedToken=new StringTokenizer(session.getValue("session_voted").toString(),";");
while(votedToken.hasMoreElements())
{
voted=votedToken.nextToken();
if(voted.equals(id))
{
votedid=true;
break;
}
}
if(votedid)
statestr="對此項目您已經投過票了,謝謝您的熱情參與!";
else
{
sqlstr="update vote set num=num+1 where id='"+id+"' and voteid='"+voteid+"'";
statement.executeUpdate(sqlstr);
voted=session.getValue("session_voted").toString();
session.putValue("session_voted",voted+id+";");
//寫入日志
sqlstr="insert into log values('','調查','投票','"+id+"','"+userid+"','"+username+"','now()','"+voteid+"')";
statement.executeUpdate(sqlstr);
}
}
else
{
sqlstr="update vote set num=num+1 where id='"+id+"' and voteid='"+voteid+"'";
statement.executeUpdate(sqlstr);
session.putValue("session_voted",voted+id+";");
//寫入日志
sqlstr="insert into log values('','調查','投票','"+id+"','"+userid+"','"+username+"','now()','"+voteid+"')";
statement.executeUpdate(sqlstr);
}
}
%>
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=gb2312">
<META HTTP-EQUIV="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" content="no-store">
<LINK rel="stylesheet" type="text/css" href="/css/style.css">
<title>投票結果</title>
</head>
<body class="mainBody">
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="35">
<tr>
<td width="25"><img src="../images/space.gif" width="25"></td>
<td width="76"><img src="../images/title_head.gif" width="76" height="35"></td>
<td width="100%" background="../images/title_bg.gif" valign="bottom">
<font size="3" face="黑體" color="#6600CC"> 投 票 結 果 </font>
<font size="2" color="#FF6600" face="Arial, Helvetica, sans-serif">——<%=title%></font>
</td>
</tr>
</table>
<table cellspacing=1 cellpadding=0 border=0 bordercolordark=#FFFFFF width="100%">
<tr height=20>
<td width="50" background="" valign="middle" align="center"> </td>
<td width="150" background="" valign="middle" align="center">
<!--Menu Table Start-->
<div align="center">
<table border="0" cellpadding="5" cellspacing="1" width="145">
<tr>
<td colspan=2 width="100%" bgcolor="" height="40" nowrap> <font color="#cc6633"><b>調查項目</b></font></td>
</tr>
<%
sqlstr="select count(*) from vote where id='"+id+"'";
result=statement.executeQuery(sqlstr);
int count=0;
if(result.next())
count=result.getInt(1);
sqlstr="select brif,num from vote where id='"+id+"' order by voteid";
result=statement.executeQuery(sqlstr);
if(result.next())
{
%>
<tr>
<td colspan=2 width="100%" height=40 valign="middle" align="left">
<font color="#6600CC"> <%=result.getString("brif")%></font>
</td>
</tr>
<%
}
int i=1;
int[] numarray=new int[count];
int numcount=0;
while(result.next())
{
numarray[i]=result.getInt("num");
numcount+=result.getInt("num");
%>
<tr>
<td width=5% height=30 align=center><font color="#6600CC"><%=i%></font></td>
<td width="95%" height="30" align="left"><font color="#6600CC"><%=result.getString("brif")%></font></td>
</tr>
<%
i++;
}
%>
</table>
</div>
</td>
<td valign="middle">
<table border=0 cellpadding="5" cellspacing="1">
<tr>
<td height=40 colspan=2 valign="middle" align="left"><font color="#cc6633"><b>
·<%=statestr%></b></font>
</td>
</tr>
<tr>
<td height=40 colspan=2 align="left"><font color="#6600CC"><b>投票結果(調查項目在左邊) <font color="">(共<%=numcount%>票)</font></b></font></td>
</tr>
<%
int imagewidth=0;
for(int j=1;j<i;j++)
{
NumberFormat f = DecimalFormat.getInstance();
((DecimalFormat)f).applyPattern("#.##");
float m=(float)numarray[j]/(float)numcount*100;
imagewidth=(int)m*4;
String percent=f.format(m);
%>
<tr>
<td height=30 >:</td>
<td><image src="/images/vote.jpg" width=<%=imagewidth%> height=10 border=0> (<font color=red><%=numarray[j]%>票</font>,<font corlor=blue><%=percent%>%</font>)</td>
</tr>
<%}%>
</table>
</td>
</tr>
</table>
<!--***************************主體表格分界*****************************-->
</body>
</html>
<%
}
catch(Exception e)
{
response.sendRedirect("voteadmin.jsp?statestr=3");
return;
}
finally
{
try{
if(result!=null)
{
result.close();
result=null;
}
if(statement!=null)
{
statement.close();
statement=null;
}
if(con!=null)
{
con.close();
con=null;
}
}catch(Exception e){}
}
%>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -