Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement page CAPTCHA by JSP

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "JSP how to achieve page CAPTCHA", the content is easy to understand, clear, hope to help you solve doubts, the following let Xiaobian lead you to study and learn "JSP how to achieve page CAPTCHA" this article.

Implementation of JSP page CAPTCHA

First add a link to the JSP page to generate the picture

Src needs to be implemented by ourselves, and the implementation logic is as follows

After running, the jsp page will issue a "auth/code" request to generate the CAPTCHA, and place the CAPTCHA in session for verification. The running effect is as follows

We add the input box and submit button to the jsp page to input the CAPTCHA, and then click the button to judge the CAPTCHA.

The background will compare the received CAPTCHA with the CAPTCHA placed in session, and output the result to the JSP page for corresponding processing. If it fails, the CAPTCHA will be refreshed.

Finally, the relatively complete page and logic have been implemented, with the following code

JSP page code

Title function submitForm () {var inputCode=$ ("# authCode") .attr ("value"); var list= {"inputCode": inputCode} $.ajax ({/ / request method type: "POST", / / request media type contentType: "application/x-www-form-urlencoded", / / request address url: "auth/checkCode", / / data Json string data: list, dataType: "json", / / request succeeded success: function (result) {alert (result) If (result== "1") {alert ("Verification passed");} else {alert ("Verification failed, refresh the verification code"); flushAuthCode () }}, / / request failed with specific error message error: function (e) {alert (e.responseText);}}) } function flushAuthCode () {/ / refresh CAPTCHA $("# codeImage") .attr ("src", "auth/authCode?abc=" + Math.random ());}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report