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

📄 result_jsp.java

📁 JAVA写的一个非常完美的在线投票系统,附带使用方法.
💻 JAVA
字号:
package org.apache.jsp.admin;

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

public final class result_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;

  static {
    _jspx_dependants = new java.util.Vector(1);
    _jspx_dependants.add("/admin/check.jsp");
  }

  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");

//ÑéÖ¤¹ÜÀíÔ±ÊÇ·ñÒѾ­µÇ½
  if((String)session.getValue("Enter")!="true")
   {
     String errmsg="error2";
     response.sendRedirect("login.jsp?errmsg="+errmsg);
   }

      out.write('\r');
      out.write('\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("    <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");
      out.write("\r\n");
      out.write("\r\n");

 ResultSet rs=null;
 int questionid = Integer.parseInt(request.getParameter("questionid"));
 String sqlstring = "SELECT Question, Date from questions where QuestionID ="+questionid;
 rs = sqltest.executeQuery(sqlstring);
 while(rs.next())
 {
  String question = rs.getString(1);
  String date = rs.getString(2);
  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;
 rs = sqltest.executeQuery(sqlstring);
 int totalcount = 0;
 while(rs.next())
 {
  totalcount += rs.getInt(1);
 }
 if(totalcount==0)
 {
  out.print("暂时还没有人参加本题投票");
  sqlstring = "SELECT Item, ItemCount FROM Items where QuestionID ="+questionid;
  rs = sqltest.executeQuery(sqlstring);
  String item;
  int itemcount;
  String percent;
  while(rs.next())
  {
   item = rs.getString(1);
   itemcount = rs.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.jpg width = "+Float.parseFloat(percent)+ " height = 10>"+ percent+"%");
   out.print("</tr>");
  }
 }
 else
 {
  out.print("共有"+totalcount+"人参加本题投票");
  sqlstring = "SELECT Item, ItemCount FROM Items where QuestionID ="+questionid;
  rs = sqltest.executeQuery(sqlstring);
  String item;
  int itemcount;
  String percent;
  while(rs.next())
  {
   item = rs.getString(1);
   itemcount = rs.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("<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 + -