コード例 #1
0
ファイル: img_jsp.java プロジェクト: qq494679975/house
  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);
    }
  }
コード例 #2
0
  // Process the request
  private String processRequest(HttpServletRequest request, HttpServletResponse response) {
    HttpSession session = request.getSession();
    String userIDs = (String) session.getAttribute("user.id");
    userIDs = (userIDs != null && userIDs.compareTo(" ") > 0) ? userIDs : "0";
    long userID = Long.parseLong(userIDs);
    String command = request.getParameter("command");
    String template = request.getParameter("template");
    String pageHash = request.getParameter("pagehash");
    String pageTitle = request.getParameter("pagetitle");
    String pageDescription = request.getParameter("pagedescription");

    String outLine = "";
    String nextScript = request.getParameter("nextscript");
    OutputStream toClient;
    boolean success = false;

    // System.out.println("userid=" + userID + ", id=" + id + ", command=" + command);

    command = (command != null && command.compareTo(" ") > 0) ? command : "form";
    nextScript = (nextScript != null && nextScript.compareTo(" ") > 0) ? nextScript : "simple1.jsp";

    //    inputstring = (inputstring != null && inputstring.compareTo(" ") > 0) ? inputstring : "";

    DbConn myConn = null;
    try {

      Context initCtx = new InitialContext();
      // String csiSchema = (String) initCtx.lookup("java:comp/env/csi-schema-path");
      // String acronym = (String) initCtx.lookup("java:comp/env/SystemAcronym");
      myConn = new DbConn();
      String csiSchema = myConn.getSchemaPath();
      if (userID != 0) {
        if (command.equals("add")) {
          outLine = "";
        } else if (command.equals("update")) {
          outLine = "";
        } else if (command.equals("updatepage")) {
          UHash uPage = new UHash(pageHash, myConn);
          // System.out.println("Got Here 1");
          if (template.equals("simple1")) {
            TextItem title = new TextItem(uPage.get("title"), myConn);
            title.setText(pageTitle);
            title.save(myConn);
            TextItem description = new TextItem(uPage.get("description"), myConn);
            description.setText(pageDescription);
            description.save(myConn);
          } else if (template.equals("simple2")) {
          }

        } else if (command.equals("test")) {
          outLine = "test";
        }
        success = true;
      }

    } catch (IllegalArgumentException e) {
      outLine = outLine + "IllegalArgumentException caught: " + e.getMessage();
      ALog.logActivity(userID, "csi", 0, pageHash + " error: '" + outLine + "'");
      // log(outLine);
    } catch (NullPointerException e) {
      outLine = outLine + "NullPointerException caught: " + e.getMessage();
      ALog.logActivity(userID, "csi", 0, pageHash + " error: '" + outLine + "'");
      // log(outLine);
    }

    // catch (IOException e) {
    //    outLine = outLine + "IOException caught: " + e.getMessage();
    //    ALog.logActivity(userID, "csi", 0, pageHash + " error: '" + outLine + "'");
    //    //log(outLine);
    // }

    catch (Exception e) {
      outLine = outLine + "Exception caught: " + e.getMessage();
      ALog.logActivity(userID, "csi", 0, pageHash + " error: '" + outLine + "'");
      // log(outLine);
    } finally {
      try {
        generateResponse(outLine, command, nextScript, success, response);
      } catch (Exception i) {
      }

      myConn.release();
      // log("Test log message\n");
    }

    return outLine;
  }
コード例 #3
0
ファイル: doRoles.java プロジェクト: weatchley/classic-java
  // Process the request
  private String processRequest(HttpServletRequest request, HttpServletResponse response) {
    String command = request.getParameter("command");
    String id = request.getParameter("id");
    String description = request.getParameter("description");
    String status = request.getParameter("rstatus");
    status = (status != null && status.compareTo(" ") > 0) ? status : null;
    String outLine = "";
    // String nextScript = "home.jsp";
    String nextScript = request.getParameter("nextscript");
    OutputStream toClient;
    HttpSession session = request.getSession();
    boolean success = false;
    String userIDs = (String) session.getAttribute("user.id");
    long userID = Long.parseLong(userIDs);

    command = (command != null && command.compareTo(" ") > 0) ? command : "form";
    nextScript = (nextScript != null && nextScript.compareTo(" ") > 0) ? nextScript : "roles.jsp";

    //    inputstring = (inputstring != null && inputstring.compareTo(" ") > 0) ? inputstring : "";

    DbConn myConn = null;
    try {

      Context initCtx = new InitialContext();
      // String csiSchema = (String) initCtx.lookup("java:comp/env/csi-schema-path");
      String acronym = (String) initCtx.lookup("java:comp/env/SystemAcronym");
      myConn = new DbConn();
      String csiSchema = myConn.getSchemaPath();
      if (command.equals("add")) {
        Role item = new Role();
        item.setDescription(description);
        item.setStatus(status);
        getPermissions(request, item);
        getPositions(request, item);
        item.add(myConn, userID);
        GlobalMembership.refresh(myConn);
        success = true;
        outLine = "";

      } else if (command.equals("update")) {
        Role item = new Role(myConn, Long.parseLong(id));
        item.setDescription(description);
        item.setStatus(status);
        getPermissions(request, item);
        getPositions(request, item);
        item.save(myConn, userID);
        GlobalMembership.refresh(myConn);
        success = true;
        outLine = "";
      } else if (command.equals("drop")) {
        Role item = new Role(myConn, Long.parseLong(id));
        item.drop(myConn, userID);
        success = true;
        outLine = "Role " + item.getDescription() + " Removed";
      } else if (command.equals("test")) {
        outLine = "test";
      }

    } catch (IllegalArgumentException e) {
      outLine = outLine + "IllegalArgumentException caught: " + e.getMessage();
      ALog.logActivity(userID, "csi", 0, "Role error: '" + outLine + "'");
      // log(outLine);
    } catch (NullPointerException e) {
      outLine = outLine + "NullPointerException caught: " + e.getMessage();
      ALog.logActivity(userID, "csi", 0, "Role error: '" + outLine + "'");
      // log(outLine);
    }

    // catch (IOException e) {
    //    outLine = outLine + "IOException caught: " + e.getMessage();
    //    ALog.logActivity(userID, "csi", 0, "Role error: '" + outLine + "'");
    //    //log(outLine);
    // }

    catch (Exception e) {
      outLine = outLine + "Exception caught: " + e.getMessage();
      ALog.logActivity(userID, "csi", 0, "Role error: '" + outLine + "'");
      // log(outLine);
    } finally {
      try {
        generateResponse(outLine, command, nextScript, success, response);
      } catch (Exception i) {
      }

      myConn.release();
      // log("Test log message\n");
    }

    return outLine;
  }