Java Simple Captcha Builder 放在哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2062246/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where to put Java Simple Captcha Builder?
提问by jl.
I am a newbie at java/java servlet. I need the simpleCaptcha for a form, using html and javaservlet for the code. With reference to http://simplecaptcha.sourceforge.net/extending.html.
我是 java/java servlet 的新手。我需要一个表单的 simpleCaptcha,使用 html 和 javaservlet 作为代码。参考http://simplecaptcha.sourceforge.net/extending.html.
Captcha captcha = new Captcha.Builder(200, 50)
.addText()
.addBackground()
.addNoise()
.gimp()
.addBorder()
.build(); // Required.
Where (java servlet) should I put this piece of code in order to create the captcha on html?
为了在 html 上创建验证码,我应该把这段代码放在哪里(java servlet)?
Thank you very much.
非常感谢你。
回答by Pascal Thivent
To extend SimpleCaptcha and customize your CAPTCHA, my understanding is that you'll have to create your own HttpServlet(maybe extends SimpleCaptchaServlet). To do so, I suggest to download the source codeand to look at SimpleCaptchaServletor StickyCaptchaServlet. This is what the doGet()method of SimpleCaptchaServletlooks like:
要扩展 SimpleCaptcha 并自定义您的 CAPTCHA,我的理解是您必须创建自己的HttpServlet(可能 extends SimpleCaptchaServlet)。为此,我建议下载源代码并查看SimpleCaptchaServlet或StickyCaptchaServlet。这是doGet()方法的SimpleCaptchaServlet样子:
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
Captcha captcha = new Captcha.Builder(_width, _height)
.addText()
.addBackground(new GradiatedBackgroundProducer())
.gimp()
.addNoise()
.addBorder()
.build();
CaptchaServletUtil.writeImage(resp, captcha.getImage());
req.getSession().setAttribute(NAME, captcha);
}
This should be self-explaining: create your own servlet and put your custom Captcha Builder code in the doGet()method. Then, follow the instructions of the Installingsection but, instead of using one of their servlet, declare yours in the web.xml. Finally, package/deploy your application. An example is bundled in the source distribution under examples. Check it out if you need more guidance about the structure, the dependencies and the packaging of your web application.
这应该是不言自明的:创建您自己的 servlet 并将您的自定义 Captcha Builder 代码放入doGet()方法中。然后,按照安装部分的说明进行操作,但不要使用他们的 servlet 之一,而是在web.xml. 最后,打包/部署您的应用程序。下的源代码分发中捆绑了一个示例examples。如果您需要有关 Web 应用程序的结构、依赖项和打包的更多指导,请查看它。
回答by D.C.
hey have you had a look at this page yet? http://simplecaptcha.sourceforge.net/installing.html
嘿,你看过这个页面了吗? http://simplecaptcha.sourceforge.net/installing.html
this is about as straight forward as it gets I think. This project gives you a few Capcha servlets out of the box. You just have to map them in your web.xml file. You can follow along and create the jsp that will call them.
这和我想的一样直接。该项目为您提供了一些开箱即用的 Capcha servlet。您只需将它们映射到您的 web.xml 文件中。您可以跟随并创建将调用它们的 jsp。

