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

      String path = request.getContextPath();
      String basePath =
          request.getScheme()
              + "://"
              + request.getServerName()
              + ":"
              + request.getServerPort()
              + path
              + "/";

      out.write("\r\n");
      out.write("\r\n");

      response.reset();
      response.setContentType("application/msexcel");
      response.setHeader("Content-disposition", "inline;filename=tqgbstudent.xls"); // 定义文件名
      DecimalFormat f = new DecimalFormat("#,##0.00");
      HSSFWorkbook wb = new HSSFWorkbook();
      HSSFSheet sheet = wb.createSheet("sheet1");
      String[] id = request.getParameterValues("id");
      String[] name = request.getParameterValues("name");
      String[] xuehao = request.getParameterValues("xuehao");
      String[] sex = request.getParameterValues("sex");
      String[] sszy = request.getParameterValues("sszy");
      String[] nbzy = request.getParameterValues("nbzy");
      String[] sd = request.getParameterValues("sd");
      String[] nbbd = request.getParameterValues("nbbd");
      String[] cjpm = request.getParameterValues("cjpm");
      String[] beizhu = request.getParameterValues("beizhu");
      String[] tel = request.getParameterValues("tel");

      // 以下以写表头
      // 表头为第一行
      HSSFRow row = sheet.createRow((short) 0);
      // 定义10列
      HSSFCell cell1 = row.createCell((short) 0);
      HSSFCell cell2 = row.createCell((short) 1);
      HSSFCell cell3 = row.createCell((short) 2);
      HSSFCell cell4 = row.createCell((short) 3);
      HSSFCell cell5 = row.createCell((short) 4);
      HSSFCell cell6 = row.createCell((short) 5);
      HSSFCell cell7 = row.createCell((short) 6);
      HSSFCell cell8 = row.createCell((short) 7);
      HSSFCell cell9 = row.createCell((short) 8);
      HSSFCell cell10 = row.createCell((short) 9);
      HSSFCell cell11 = row.createCell((short) 10);

      cell1.setEncoding((short) 1);
      cell1.setCellType(1);
      cell2.setEncoding((short) 1);
      cell2.setCellType(1);
      cell3.setEncoding((short) 1);
      cell3.setCellType(1);
      cell4.setEncoding((short) 1);
      cell4.setCellType(1);
      cell5.setEncoding((short) 1);
      cell5.setCellType(0);
      cell6.setEncoding((short) 1);
      cell6.setCellType(1);
      cell7.setEncoding((short) 1);
      cell7.setCellType(1);
      cell8.setEncoding((short) 1);
      cell8.setCellType(1);
      cell9.setEncoding((short) 1);
      cell9.setCellType(1);
      cell10.setEncoding((short) 1);
      cell10.setCellType(1);
      cell11.setEncoding((short) 1);
      cell11.setCellType(1);
      // 定义表头的内容
      cell1.setCellValue("序号");
      cell2.setCellValue("姓名");
      cell3.setCellValue("学号");
      cell4.setCellValue("性别");
      cell5.setCellValue("硕士专业");
      cell6.setCellValue("拟报博士专业");
      cell7.setCellValue("原硕导");
      cell8.setCellValue("拟报博导");
      cell9.setCellValue("学位课加权成绩排名");
      cell10.setCellValue("备注");
      cell11.setCellValue("联系方式");

      for (int i = 0; i < name.length; i++) {
        // 定义数据从第二行开始
        row = sheet.createRow((short) i + 1);
        cell1 = row.createCell((short) 0);
        cell2 = row.createCell((short) 1);
        cell3 = row.createCell((short) 2);
        cell4 = row.createCell((short) 3);
        cell5 = row.createCell((short) 4);
        cell6 = row.createCell((short) 5);
        cell7 = row.createCell((short) 6);
        cell8 = row.createCell((short) 7);
        cell9 = row.createCell((short) 8);
        cell10 = row.createCell((short) 9);
        cell11 = row.createCell((short) 10);

        cell1.setEncoding((short) 1);
        cell1.setCellType(1);
        cell2.setEncoding((short) 1);
        cell2.setCellType(1);
        cell3.setEncoding((short) 1);
        cell3.setCellType(1);
        cell4.setEncoding((short) 1);
        cell4.setCellType(1);
        cell5.setEncoding((short) 1);
        cell5.setCellType(0);
        cell6.setEncoding((short) 1);
        cell6.setCellType(1);
        cell7.setEncoding((short) 1);
        cell7.setCellType(1);
        cell8.setEncoding((short) 1);
        cell8.setCellType(1);
        cell9.setEncoding((short) 1);
        cell9.setCellType(1);
        cell10.setEncoding((short) 1);
        cell10.setCellType(1);
        cell11.setEncoding((short) 1);
        cell11.setCellType(1);

        // 填充内容
        cell1.setCellValue(id[i]);
        cell2.setCellValue(name[i]);
        cell3.setCellValue(xuehao[i]);
        cell4.setCellValue(sex[i]);
        cell5.setCellValue(sszy[i]);
        cell6.setCellValue(nbzy[i]);
        cell7.setCellValue(sd[i]);
        cell8.setCellValue(nbbd[i]);
        cell9.setCellValue(cjpm[i]);
        cell10.setCellValue(beizhu[i]);
        cell11.setCellValue(tel[i]);
      }
      wb.write(response.getOutputStream());
      response.getOutputStream().flush();
      response.getOutputStream().close();

    } 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);
    }
  }
Beispiel #2
0
  public void _jspService(HttpServletRequest request, HttpServletResponse response)
      throws java.io.IOException, ServletException {

    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 {
      response.setContentType("image/jpeg");
      pageContext =
          _jspxFactory.getPageContext(
              this, request, response, "/myhtml/errorpage/erroe.jsp", 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");
      out.write('\r');
      out.write('\n');

      // 设置页面不缓存
      response.setHeader("Pragma", "No-cache");
      response.setHeader("Cache-Control", "no-cache");
      response.setDateHeader("Expires", 0);

      //   在内存中创建图象
      int width = 60, height = 20;
      BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

      //   获取图形上下文
      Graphics g = image.getGraphics();

      // 生成随机类
      Random random = new Random();

      //   设定背景色
      g.setColor(getRandColor(200, 250));
      g.fillRect(0, 0, width, height);

      // 设定字体
      g.setFont(new Font("Times   New   Roman", Font.PLAIN, 18));

      // 画边框
      // g.setColor(new   Color());
      // g.drawRect(0,0,width-1,height-1);

      //   随机产生155条干扰线,使图象中的认证码不易被其它程序探测到
      g.setColor(getRandColor(160, 200));
      for (int i = 0; i < 155; i++) {
        int x = random.nextInt(width);
        int y = random.nextInt(height);
        int xl = random.nextInt(12);
        int yl = random.nextInt(12);
        g.drawLine(x, y, x + xl, y + yl);
      }

      //   取随机产生的认证码(4位数字)
      String sRand = "";
      for (int i = 0; i < 4; i++) {
        String rand = String.valueOf(random.nextInt(10));
        sRand += rand;
        //   将认证码显示到图象中
        g.setColor(
            new Color(
                20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110)));
        // 调用函数出来的颜色相同,可能是å›
        // ä¸ºç§å­å¤ªæŽ¥è¿‘,所以只能直接生成
        g.drawString(rand, 13 * i + 6, 16);
      }

      //   将认证码存入SESSION
      session.setAttribute("rand", sRand);

      //   图象生效
      g.dispose();

      //   输出图象到页面
      ImageIO.write(image, "JPEG", response.getOutputStream());
      out.clear();
      out = pageContext.pushBody();

    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)) {
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try {
            out.clearBuffer();
          } catch (java.io.IOException e) {
          }
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
        else log(t.getMessage(), t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
  public void _jspService(HttpServletRequest request, HttpServletResponse response)
      throws java.io.IOException, ServletException {

    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 {
      response.setContentType("text/html");
      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('\n');
      out.write('\n');

      response.setHeader("Pragma", "no-cache"); // HTTP 1.0
      response.setDateHeader("Expires", 0);
      response.setHeader("Cache-Control", "no-cache"); // HTTP 1.1

      String _adminid = "";
      String _adminname = "";
      String _admintype = "";
      String _admingroup = "";
      String _approval = "";
      String _adminclass = "";
      String _adminmail = "";

      try {

        _adminid = (String) session.getAttribute("adminid");

        if (_adminid == null || _adminid.length() == 0 || _adminid.equals("null")) {
          response.sendRedirect("/admin/login_first.html");
          return;
        }

        _adminname = (String) session.getAttribute("adminname");
        _admintype = (String) session.getAttribute("admintype");
        _admingroup = (String) session.getAttribute("admingroup");
        _approval = (String) session.getAttribute("approval");
        _adminclass = (String) session.getAttribute("adminclass");
        _adminmail = (String) session.getAttribute("admin_email");
        // session.setMaxInactiveInterval(60*60);

      } catch (Exception e) {
        response.sendRedirect("/admin/login_first.html");
        return;
      }

      out.write('\n');

      // response.resetBuffer();
      response.reset();

      String attachPath = request.getParameter("attachPath");
      String attachFile = request.getParameter("attachFile");
      String attachRealFile = request.getParameter("attachRealFile");

      try {

        String savePath = application.getRealPath(attachPath) + File.separator;
        File file = new File(savePath + attachRealFile);

        if (!file.exists()) {
          throw new UserDefinedException("File does not exist.");
        }

        // file read ..
        response.setContentType("application/octet-stream");
        response.setHeader("Content-Length", "" + file.length());
        response.setHeader("Content-Disposition", "attachment; filename=" + attachFile + ";");

        byte[] buf = new byte[8192];

        int cnt = 0;

        BufferedInputStream inStream = new BufferedInputStream(new FileInputStream(file));
        BufferedOutputStream outStream = new BufferedOutputStream(response.getOutputStream());

        try {
          while ((cnt = inStream.read(buf)) != -1) {
            outStream.write(buf, 0, cnt);
          }

          outStream.flush();
        } catch (Exception e) {
          throw e;
        } finally {
          if (outStream != null) outStream.close();
          if (inStream != null) inStream.close();
        }

      } catch (Exception e) {
        out.println(
            "<html><script language='javascript'>alert('" + e.getMessage() + "');</script></html>");
      }

    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)) {
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try {
            out.clearBuffer();
          } catch (java.io.IOException e) {
          }
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }