public class StickyCaptchaServlet
extends HttpServlet
CaptchaServletUtil.NAME will force a new Captcha to
be added to the session. (Obviously, this is not a perfect solution as
session IDs can simply not be passed.)
The size of the image is by default 200x50. This can be customized using the
captcha-height and captcha-width init parameters in
web.xml.
By default the CAPTCHA will expire after 600000ms. This can be overridden
using the ttl init parameter, in milliseconds.
An example showing all parameters:
<servlet>
<servlet-name>StickyCaptcha</servlet-name>
<servlet-class>nl.captcha.servlet.StickyCaptchaServlet</servlet-class>
<init-param>
<param-name>captcha-width</param-name>
<param-value>400</param-value>
</init-param>
<init-param>
<param-name>captcha-height</param-name>
<param-value>200</param-value>
</init-param>
<init-param>
<param-name>ttl</param-name>
<param-value>900000</param-value>
</init-param>
</servlet>
Since the constructed image is a PNG the servlet mapping should be defined
something like this:
<servlet-mapping>
<servlet-name>StickyCaptcha</servlet-name>
<url-pattern>/stickyCaptcha.png</url-pattern>
</servlet-mapping>| 构造器和说明 |
|---|
StickyCaptchaServlet() |
public void init(ServletConfig config)
throws ServletException
ServletExceptionpublic void doGet(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException,
IOException
Captcha and write out its image.ServletExceptionIOExceptionCopyright © 2015. All rights reserved.