Botdetect验证码HTML< taglib> [英] Botdetect Captcha HTML <taglib>
问题描述
我想将Botdetect验证码添加到我的html文件中.但是在Botdetect验证码的网站上,仅提供了jsp的示例.在此jsp文件中,< taglib>
的用法如下:
I want to add Botdetect Captcha to my html file.But in the website of the Botdetect captcha, there is example only for jsp. In this jsp file, <taglib>
is used like that:
<%@taglib prefix="botDetect" uri="https://captcha.com/java/jsp"%>
....
<botDetect:captcha id="basicExample" userInputID="captchaCode" />
<div class="validationDiv">
<input name="captchaCode" type="text" id="captchaCode" value="${basicExample.captchaCode}" />
<input type="submit" name="validateCaptchaButton" value="Validate" id="validateCaptchaButton" />
<span class="correct">${basicExample.captchaCorrect}</span>
<span class="incorrect">${basicExample.captchaIncorrect}</span>
</div>
HTML文件中是否有<%@ taglib>
的替代方法.我该如何解决这个问题?
Is there any alternative for <%@taglib>
in HTML files. How can I solve this problem?
推荐答案
我遇到了这个问题,因为我使用Thymeleaf而不是JSP,所以我不能使用taglib,但仍然有动态HTML".我正在回答,假设这是您的情况.
I'm facing this problem because I use Thymeleaf instead of JSP so I can't use the taglib but I still have "dynamic HTML". I'm answering assuming this is your case.
我在以下帮助页面上看到了可能的解决方案: https://captcha.com/doc/java/jsp-captcha.html 在第2节:
I saw a possible solution on the help pages here: https://captcha.com/doc/java/jsp-captcha.html at section 2:
<%
// Adding BotDetect Captcha to the page
Captcha captcha = Captcha.load(request, "exampleCaptcha");
captcha.setUserInputID("captchaCode");
String captchaHtml = captcha.getHtml();
out.write(captchaHtml);
%>
这是JSP代码,但可以很容易地适应Thymeleaf.这在打开页面的@Controller中:
This is JSP code but can be easily adapted to Thymeleaf. This in the @Controller that opens the page:
Captcha captcha = Captcha.load(request, "exampleCaptcha");
captcha.setUserInputID("captchaCode");
String captchaHtml = captcha.getHtml();
model.addAttribute("captchaHtml", captchaHtml);
和html就像
<th:block th:utext="${captchaHtml}"></th:block>
用于验证码检查的代码与JSP相同,但是放置在处理以下形式的@Controller中:
The code for captcha checking is the same as for JSP, but placed in the @Controller that handles the form:
// validate the Captcha to check we're not dealing with a bot
boolean isHuman = captcha.validate(request.getParameter("captchaCode"));
if (isHuman) {
// TODO: Captcha validation passed, perform protected action
} else {
// TODO: Captcha validation failed, show error message
}
要完成此操作,还需要编辑web.xml(如果有的话),并按照官方文档的说明导入Java库.我正在使用Gradle并导入'com.captcha:botdetect-servlet:4.0.beta3.7'
To finish you also need to edit web.xml (if you have it) and import the java libs as by the official docs. I'm using Gradle and importing 'com.captcha:botdetect-servlet:4.0.beta3.7'
警告:您的服务器应该位于HTTPS上,否则在使用4.0.beta3.7版本时可能会出现此错误:
Warning: your server should be on HTTPS or you might get this error when using version 4.0.beta3.7:
未设置Captcha.UserInputID.您对BotDetect的实现是尚未完全安全
Captcha.UserInputID is not set. Your implementation of BotDetect is not completely secure yet
这篇关于Botdetect验证码HTML< taglib>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!