【问题标题】:Implementing Captcha in GWT-Ext 2.0.3在 GWT-Ext 2.0.3 中实现验证码
【发布时间】:2011-09-28 16:20:45
【问题描述】:

大家好,
我正在使用 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 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>
    

  • 我的 GWT 面板
  • FormPanel formPanel = new FormPanel();
    Image captchaImage = new Image("/SimpleCaptcha.jpg");
    formPanel.add(captchaImage);
    

    每次我从浏览器刷新页面时,它都会显示新的验证码图像。但是当我重新加载表单面板时它不显示图像。


    谁能帮帮我?

    【问题讨论】:

    • 使用recaptcha,会比这个更安全。

    标签: java security captcha gwt-ext simplecaptcha


    【解决方案1】:

    尝试添加“时间戳”

    Image captchaImage = new Image("/SimpleCaptcha.jpg?" + Math.floor(Math.random()*100));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-04
      • 1970-01-01
      • 2010-11-17
      • 2017-10-25
      • 2016-04-25
      相关资源
      最近更新 更多