Java 在GWT Ext 2.0.3中实现验证码
大家好,Java 在GWT Ext 2.0.3中实现验证码,java,security,captcha,gwt-ext,simplecaptcha,Java,Security,Captcha,Gwt Ext,Simplecaptcha,大家好, 我正在使用GWT Ext 2.0.3。我已经在我的项目中实现了SimpleCaptcha。重新加载面板时,我无法刷新验证码图像。我正在使用SimpleCaptcha-1.2.1.jar文件来实现验证码。 我创建了一个servlet来显示验证码图像。 import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import
我正在使用GWT Ext 2.0.3。我已经在我的项目中实现了SimpleCaptcha。重新加载面板时,我无法刷新验证码图像。我正在使用SimpleCaptcha-1.2.1.jar文件来实现验证码。
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import nl.captcha.Captcha;
import nl.captcha.backgrounds.GradiatedBackgroundProducer;
import nl.captcha.servlet.CaptchaServletUtil;
import nl.captcha.servlet.SimpleCaptchaServlet;
public class ExtendedCaptchaServlet extends SimpleCaptchaServlet {
private static final long serialVersionUID = -3280477565969758716L;
//@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
HttpSession session = req.getSession();
Captcha captcha = new Captcha.Builder(200, 50)
.addText()
.addBackground(new GradiatedBackgroundProducer()).addNoise()
.addBorder()
.build();
session.setAttribute("captcha", captcha);
CaptchaServletUtil.writeImage(resp, captcha.getImage());
}
}
web.xml中的条目
<servlet>
<servlet-name>SimpleCaptcha</servlet-name>
<servlet-class> com.server.test.ExtendedCaptchaServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SimpleCaptcha</servlet-name>
<url-pattern>/SimpleCaptcha.jpg</url-pattern>
</servlet-mapping>
每次我从浏览器刷新页面时,它都会显示新的验证码图像。但当我重新加载表单面板时,它不会显示图像
有人能帮我吗?尝试添加“时间戳” 尝试添加“时间戳”
使用recaptcha,它将比此更安全。使用recaptcha,它将比此更安全。
FormPanel formPanel = new FormPanel();
Image captchaImage = new Image("/SimpleCaptcha.jpg");
formPanel.add(captchaImage);
Image captchaImage = new Image("/SimpleCaptcha.jpg?" + Math.floor(Math.random()*100));