2

Hello All,
I am using GWT-Ext 2.0.3. I have implemented SimpleCaptcha in my project.I am not able to refresh the captcha image when I reload the panel.I am using simplecaptcha-1.2.1.jar file to implemet captcha.

  • I have created a servlet to display captcha image.
  • 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());
    
        }
    }
    

  • Entry in 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>
    

  • My GWT Panel
  • FormPanel formPanel = new FormPanel();
    Image captchaImage = new Image("/SimpleCaptcha.jpg");
    formPanel.add(captchaImage);
    

    It is displays the new captcha image each time when I refresh the page from browser. But it does not display the image when I reload the form panel.


    Can anyone help me?

    Roman C
    • 49,761
    • 33
    • 66
    • 176
    JankiPanwala
    • 584
    • 1
    • 4
    • 20

    1 Answers1

    0

    try to add "timestamp"

    Image captchaImage = new Image("/SimpleCaptcha.jpg?" + Math.floor(Math.random()*100));
    
    pbaris
    • 4,525
    • 5
    • 37
    • 61