2011-07-05 55 views
2

大家好,
我正在使用GWT-Ext 2.0.3。我在我的項目中實現了SimpleCaptcha。當我重新加載面板時,我無法刷新驗證碼圖像。我正在使用simplecaptcha-1.2.1.jar文件來實現驗證碼。
在GWT-Ext 2.0.3中實現驗證碼

  • 我創建了一個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); 
    

    這是顯示新的驗證碼圖像,每次當我刷新瀏覽器從頁面。但是,當我重新加載表單面板時,它不顯示圖像。


    誰能幫助我?

    +0

    使用驗證碼,它會比這更安全。 – Mikey

    回答

    0

    嘗試添加「時間戳」

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