📄 votting.java
字号:
package test;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Votting extends HttpServlet {
DBConn conn=new DBConn();
ResultSet rs1=null;
ResultSet rs2=null;
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html;charset=GBK");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>投票失败</title>");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
try{
String ip=request.getRemoteAddr();
String topicid=request.getParameter("topicid");
String pp=request.getParameter("p");
int i=0;
if(!HadVoted(ip))
{
String sql1="UPDATE votes SET result=result+1,ip=CONCAT(ip,'"+
ip+"','#') WHERE type>0 AND topicid="+topicid;
conn.update(sql1);
String sql3="UPDATE votes SET result=result+1 WHERE type=0 AND id="+pp;
conn.update(sql3);
response.sendRedirect("ListVotes");
}
else
{
out.print("<B>您已经投过票了!不能重复投票.</B><BR>");
out.print("<B>IP:</B>"+ip);
}
}
catch(Exception e)
{
out.print(e.toString());
}
out.println("</body>");
out.println("</html>");
}
public boolean HadVoted(String ip)
{
boolean flag=false;
String sql2="SELECT * FROM votes WHERE ip REGEXP '#"+ip+"#'";
try{
rs2=conn.query(sql2);
if(rs2.next())
flag=true;
rs2.close();
}
catch(Exception ex)
{
System.out.print(ex.toString());
}
return flag;
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
doGet(request,response);
}
public void destroy()
{
conn=null;
rs1=null;
rs2=null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -