Search code examples
javaservletscaptchasimplecaptcha

simplecaptcha image only served after reload


I'm using SimpleCaptcha to secure our contact form. It works well, but only after reloading the page.

The Servlet is nl.captcha.servlet.StickyCaptchaServlet, so it should not change the image after reloads. But when first opening the page the image is just not loaded. However, after reloading everything works fine.

the web.xml

The captcha is served by an application running at /services.

<web-app>
  <servlet>
    <servlet-name>captcha</servlet-name>
    <servlet-class>nl.captcha.servlet.StickyCaptchaServlet<servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>captcha</servlet>
    <url-pattern>/captcha.png</url-pattern>
  </servlet-mapping>
</web-app>

the html

<img src="/services/captcha.png">

the server

I'm using tomcat-7.0.34 on a Windows 7 64bit machine with Java 1.7.0_07.

the question

Why does the image only show up after a reload? Any ideas?


Solution

  • Just do this way to by pass what emka86 had said.

    <img src="/services/captcha.png" style="display:none"> (Duplicate part to fix the issue)
    
    <img src="/services/captcha.png"> (The actual one)
    

    Hope this helps for any future developer out there.