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

📄 showresult_jsp.java

📁 在线投票系统,利用JSP技术来开发,方便大家使用
💻 JAVA
字号:
package org.apache.jsp.admin;

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

public final class showresult_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {


 String printf(String str)  //转换百分比格式
 {
  int index=0;
  if((index=str.indexOf(".")) != -1)
   str = str.substring(0,index) +"."+ str.substring(index+1,index+3);
  return(str);
 }

  private static java.util.Vector _jspx_dependants;

  public java.util.List getDependants() {
    return _jspx_dependants;
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    JspFactory _jspxFactory = null;
    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;


    try {
      _jspxFactory = JspFactory.getDefaultFactory();
      response.setContentType("text/html;charset=GB2312");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\r\n");
      out.write("\r\n");
      database.opendata sqltest = null;
      synchronized (_jspx_page_context) {
        sqltest = (database.opendata) _jspx_page_context.getAttribute("sqltest", PageContext.PAGE_SCOPE);
        if (sqltest == null){
          sqltest = new database.opendata();
          _jspx_page_context.setAttribute("sqltest", sqltest, PageContext.PAGE_SCOPE);
          out.write('\r');
          out.write('\n');
        }
      }
      out.write('\r');
      out.write('\n');
      out.write("\r\n");
      out.write("\r\n");
      out.write("<html>\r\n");
      out.write("<head>\r\n");
      out.write("<title>查看结果</title>\r\n");
      out.write("<LINK href=\"style.css\" rel=stylesheet>\r\n");
      out.write("</head>\r\n");
      out.write("<body>\r\n");
      out.write("\r\n");

 String question,date,Sqlstring;
 ResultSet rs=null;
 ResultSet rs1=null;
 ResultSet rs2=null;

 int questionid = 0;
 Sqlstring = "SELECT Question, Date, QuestionID from questions where IsVisable = 1 and IsOpen= 1";
 rs=sqltest.executeQuery(Sqlstring);
 /*
 Statement _smt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
 ResultSet _rs;
 Statement _smt_=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
 ResultSet _rs_;
*/
 while(rs.next())
 {
      out.write("\r\n");
      out.write("      <TABLE bgcolor=#999999 cellSpacing=0 cellPadding=0 width=100% border=1>\r\n");
      out.write("      <TBODY>\r\n");
      out.write("      <TR bgColor=#999999>\r\n");
      out.write("        <TD colSpan=10>\r\n");


  question = rs.getString(1);
  date = rs.getString(2);
  questionid = rs.getInt(3);
  out.print("<p align=center>"+date+"发布</td></tr>");
  out.print("<TR bgColor=#999999><TD colSpan=10>"+question+"</td></tr>");

      out.write("\r\n");
      out.write("  <TABLE cellSpacing=0 cellPadding=0 width=100% align=center border=1 bgcolor=\"#999999\">\r\n");
      out.write("            <TBODY>\r\n");
      out.write("            <TR>\r\n");
      out.write("\r\n");
      out.write("            <TD width=\"45%\">\r\n");
      out.write("              <div align=\"center\">选项</div>\r\n");
      out.write("                </TD>\r\n");
      out.write("\r\n");
      out.write("            <TD width=\"4%\">\r\n");
      out.write("              <div align=\"center\">记数</div>\r\n");
      out.write("            </TD>\r\n");
      out.write("\r\n");
      out.write("            <TD width=\"51%\">\r\n");
      out.write("              <div align=\"center\">图示</div>\r\n");
      out.write("            </TD>\r\n");
      out.write("            </TR>\r\n");

  Sqlstring = "SELECT ItemCount From Items Where QuestionID ="+questionid;
  rs1 = sqltest.executeQuery(Sqlstring);
  int totalcount = 0;
  while(rs1.next())
  {
   totalcount += rs1.getInt(1);
  }
  if(totalcount==0)
  {
   out.print("暂时还没有人参加本题投票");
   Sqlstring = "SELECT Item, ItemCount FROM Items where QuestionID ="+questionid;
   rs2 = sqltest.executeQuery(Sqlstring);
   String item;
   int itemcount;
   String percent;
   while(rs2.next())
   {
    item = rs2.getString(1);
    itemcount = rs2.getInt(2);
    percent = printf(String.valueOf((double)itemcount/totalcount*100)+"0");
    out.print("<tr><td>"+item+"</td>");
    out.print("<td align=center>"+itemcount+"</td>");
    out.print("</tr>");
   }
  }
  else
  {
   out.print("共有"+totalcount+"人参加本题投票");
   Sqlstring = "SELECT Item, ItemCount FROM Items where QuestionID ="+questionid;
   rs2 = sqltest.executeQuery(Sqlstring);
   String item;
   int itemcount;
   String percent;
   while(rs2.next())
   {
    item = rs2.getString(1);
    itemcount = rs2.getInt(2);
    percent = printf(String.valueOf((double)itemcount/totalcount*100)+"0");
    out.print("<tr><td>"+item+"</td>");
    out.print("<td align=center>"+itemcount+"</td>");
    out.print("<td><img src = bar.gif width = "+Float.parseFloat(percent)*2+ " height = 10>"+ percent+"%");
    out.print("</tr>");
   }
  }


      out.write("\r\n");
      out.write("</table>\r\n");
      out.write("</table>\r\n");
      out.write("<p>\r\n");
}
      out.write("\r\n");
      out.write("<p>\r\n");
      out.write("<hr>\r\n");
      out.write("<p>\r\n");
      out.write("<div align=\"center\"><a href=\"Javascript:window.close();\">关闭窗口</a></div>\r\n");
      out.write("\r\n");
      out.write("</body>\r\n");
      out.write("</html>\r\n");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          out.clearBuffer();
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}

⌨️ 快捷键说明

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