產生"登入驗證碼"的方法步驟

來源:互聯網
上載者:User

標籤:驗證碼   package   import   

1.添加simplecaptcha架包簡單夠用的驗證碼生產庫.2.新增CaptchaModule模組類

public class CaptchaModule {        @At    @Ok("raw:png")        public BufferedImage next(HttpSession session, @Param("w") int w,@Param("h") int h) {            if (w * h < 1) { //長或寬為0?重設為預設長寬.            w = 200;            h = 60;        }        Captcha captcha = new Captcha.Builder(w, h)                                .addText().addBackground(new GradiatedBackgroundProducer())                                .gimp(new FishEyeGimpyRenderer())                                .build();        String text = captcha.getAnswer();        session.setAttribute(Toolkit.captcha_attr, text);        return captcha.getImage();    }}


  • raw代表RawView

  • png是RawView中對image/png的縮寫,是資料mime的描述

  • 傳回值是BufferedImage,且這是image/png, 所以會轉為圖片顯示. 還支援jpg/webp等格式,詳情參考RawView的源碼吧.

  • Captcha有N多的組合和配置,自行選擇啦

3.在頁面中加入驗證碼文字框

<script type="text/javascript">            function next_captcha() {                $("#captcha_img").attr("src", "${base}/captcha/next?_=" + new Date().getTime());             }        </script>        驗證碼<input name="captcha" type="text" value="">        <img id="captcha_img" onclick="next_captcha();return false;" src="${base}/captcha/next"></img>

650) this.width=650;" src="http://img.baidu.com/hi/jx2/j_0003.gif" alt="j_0003.gif" />650) this.width=650;" src="http://img.baidu.com/hi/jx2/j_0005.gif" alt="j_0005.gif" />


本文出自 “12403903” 部落格,轉載請與作者聯絡!

產生"登入驗證碼"的方法步驟

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.