⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 listvotes.java

📁 一本jsp自学教材
💻 JAVA
字号:
package test;

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ListVotes 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\">");
        
        String sql1="SELECT * FROM votes WHERE type>0";
       try{
        rs1=conn.query(sql1);
        out.print("<TABLE BORDER=1 bordercolorlight=#000000 >");
        while(rs1.next())
         {
          int topicid=rs1.getInt("topicid");
          int total=rs1.getInt("result"); 
          out.print("<FORM method=post action=Votting>");
          out.print("<TR><TD colspan=4>");
          out.print("投票项目:"+rs1.getString("title"));
          out.print("</TD></TR>");
          out.print(getItems(topicid,total).toString());
          out.print("<INPUT type=hidden name=topicid value='"+topicid+"'/>");
          out.print("<TR><TD colspan=4 align=right><INPUT type=submit value=\"投票\">");
          out.print("</TD></TR></FORM >");
         }
        out.print("</TABLE>");
        rs1.close();
        }
        catch(Exception e)
         {
             out.print(e.toString());
         }
        out.println("</body>");
        out.println("</html>");
    }
    public StringBuffer getItems(int topicid,int total)
     {
       StringBuffer buffer=new StringBuffer();
       String sql2="SELECT * FROM votes WHERE type=0 AND topicid="+topicid;
      try{
       rs2=conn.query(sql2);
       int m=1;
       while(rs2.next())
        {
         buffer.append("<TR><TD>"+m+"</TD>");
         buffer.append("<TD>"+rs2.getString("title")+"</TD>");
         int hl=400*rs2.getInt("result")/total;     
         buffer.append("<TD><IMG src='DrawVote?hl="+hl+"&color="+m+"' /></TD><TD>");
         buffer.append("<INPUT type=\"radio\" name=\"p\" value=\""+rs2.getInt("id")+"\">");
         buffer.append("</TD></TR>");
         m++;
        }
       rs2.close();      
      }
      catch(Exception ex)
       {
          System.out.print(ex.toString());
       }
       return buffer;
     }
    public void doPost(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {  
      doGet(request,response);    
    }
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -