String strTblName = "votemessage";//表名
 String strID = ACommFun.DecodeMsg(ACommFun.TrimString(request.getParameter("ID")));String strIPAddr = request.getRemoteAddr();

strSQL = "Select ID From voteip Where IPAddr='"+strIPAddr+"' And now()<DATE_ADD(VoteTime, INTERVAL 1 DAY) ";
rset = stmt.executeQuery(strSQL);
boolean bVoted = rset.next();
    rset.close();

String strEndDate = "";
String strIniPath = getServletContext().getRealPath("EventMUEndDate.ini");
DataInputStream dis = new DataInputStream(
  new BufferedInputStream( new FileInputStream(strIniPath)) );
strEndDate = dis.readLine();
strEndDate = strEndDate==null?"":strEndDate;
dis.close();
String strCurDate = (new java.text.SimpleDateFormat("yyyyMMddHHmm")).format(new java.util.Date()); if(strCurDate.compareTo(strEndDate)>=0)
{
%>
<br />
<div style="font-weight:bold; font-size:16px; color:#F00;">投票已经结束!</div>
<%
}
else if(bVoted)
{
%>
<br />
<div style="font-weight:bold; font-size:16px; color:#F00;">一天之内不能投票2次以上!</div>
<%
}
else
{

strSQL = "Insert Into voteip Set VoteID="+strID+", IPAddr='"+strIPAddr+"', VoteTime=now() ";
stmt.execute(strSQL); strSQL = "Update "+strTblName+" Set VoteNum=VoteNum+1 Where ID="+strID;
stmt.execute(strSQL);
%>
<br />
<div style="font-weight:bold; font-size:16px; color:#F00;">投票成功!</div>
<%
}
%>
<br />
<a href="VoteMessage.jsp">返回上一页。</a></div>主要想知道他是怎样设置投票的时间段的,怎样控制投票结束的?

解决方案 »

  1.   

    String strIniPath = getServletContext().getRealPath("EventMUEndDate.ini");//这文件里是应该有投票截止日期
    DataInputStream dis = new DataInputStream(
    new BufferedInputStream( new FileInputStream(strIniPath)) );
    strEndDate = dis.readLine();
    strEndDate = strEndDate==null?"":strEndDate;//拿到投票截止日期
    dis.close();
    String strCurDate = (new java.text.SimpleDateFormat("yyyyMMddHHmm")).format(new java.util.Date());//获取当前日期if(strCurDate.compareTo(strEndDate)>=0)//当前日期与截止日期比较,大于截止日期,就投票结束
    {