<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## 在Sevlet中使用 ``` public class ValidateColor extends HttpServlet { private static final long serialVersionUID = 1L; //session的name值 。。。CHECK_CODE_KEY public static final String CHECK_CODE_KEY = "CHECK_CODE_KEY"; //設置驗證圖片的寬度, 高度, 驗證碼的個數 private int width = 152; private int height = 40; //驗證碼中的代碼的個數 。ASDsC ABsE private int codeCount = 4; //驗證碼字體的高度 private int fontHeight = 4; //驗證碼中的單個字符基線. 即:驗證碼中的單個字符位于驗證碼圖形左上角的 (codeX, codeY) 位置處 private int codeX = 0; private int codeY = 0; //驗證碼由哪些字符組成 char [] codeSequence = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz23456789".toCharArray(); //初始化驗證碼圖形屬性 public void init(){ fontHeight = height - 2; codeX = width / (codeCount + 2); codeY = height - 4; } @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub //定義一個類型為 BufferedImage.TYPE_INT_BGR 類型的圖像緩存 BufferedImage buffImg = null; buffImg = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR); //在 buffImg 中創建一個 Graphics2D 圖像 Graphics2D graphics = null; graphics = buffImg.createGraphics(); //設置一個顏色, 使 Graphics2D 對象的后續圖形使用這個顏色 graphics.setColor(Color.WHITE); //填充一個指定的矩形: x - 要填充矩形的 x 坐標; y - 要填充矩形的 y 坐標; width - 要填充矩形的寬度; height - 要填充矩形的高度 graphics.fillRect(0, 0, width, height); //創建一個 Font 對象: name - 字體名稱; style - Font 的樣式常量; size - Font 的點大小 Font font = null; font = new Font("", Font.BOLD, fontHeight); //使 Graphics2D 對象的后續圖形使用此字體 graphics.setFont(font); graphics.setColor(Color.BLACK); //繪制指定矩形的邊框, 繪制出的矩形將比構件寬一個也高一個像素 graphics.drawRect(0, 0, width - 1, height - 1); //隨機產生 15 條干擾線, 使圖像中的認證碼不易被其它程序探測到 Random random = null; random = new Random(); graphics.setColor(Color.GREEN); for(int i = 0; i < 55; i++){ int x = random.nextInt(width); int y = random.nextInt(height); int x1 = random.nextInt(20); int y1 = random.nextInt(20); graphics.drawLine(x, y, x + x1, y + y1); } //創建 randomCode 對象, 用于保存隨機產生的驗證碼, 以便用戶登錄后進行驗證 StringBuffer randomCode; randomCode = new StringBuffer(); for(int i = 0; i < codeCount; i++){ //得到隨機產生的驗證碼數字 String strRand = null; strRand = String.valueOf(codeSequence[random.nextInt(36)]); //把正在產生的隨機字符放入到 StringBuffer 中 randomCode.append(strRand); //用隨機產生的顏色將驗證碼繪制到圖像中 graphics.setColor(Color.BLUE); graphics.drawString(strRand, (i + 1)* codeX, codeY); } //再把存放有所有隨機字符的 StringBuffer 對應的字符串放入到 HttpSession 中 request.getSession().setAttribute(CHECK_CODE_KEY, randomCode.toString()); //禁止圖像緩存 response.setHeader("Pragma", "no-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); //將圖像輸出到輸出流中 ServletOutputStream sos = null; sos = response.getOutputStream(); ImageIO.write(buffImg, "jpeg", sos); sos.close(); } } ``` ## 在springMVC中使用 https://www.cnblogs.com/moonlightL/p/7282469.html
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看