vote.jsp

来自「投票管理的页面代码」· JSP 代码 · 共 197 行

JSP
197
字号
<%@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>&nbsp;<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>投票结果(调查项目在左边)&nbsp;<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>&nbsp;(<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 + =
减小字号Ctrl + -
显示快捷键?