Menu

#4 Cache Fix

open
nobody
None
5
2006-08-31
2006-08-31
No

You may not have noticed, but the SimpleCaptcha doe
snot properly set the no-cache headers on the servlet
response stream. Therefore in Opera, you will get the
same image, which often does not match the session
key...That's not good.

You need to change the doGet method of the
nl.captcha.servlet.Captcha file from this:

public void doGet(HttpServletRequest
httpservletrequest, HttpServletResponse
httpservletresponse)
throws ServletException, IOException
{
String s = textProducer.getText();
httpservletrequest.getSession().setAttribute
("SIMPLE_CAPCHA_SESSION_KEY", s);
DefaultCaptchaIml defaultcaptchaiml = new
DefaultCaptchaIml(props);
defaultcaptchaiml.createImage
(httpservletresponse.getOutputStream(), s);
}

to this:

public void doGet(HttpServletRequest
httpservletrequest, HttpServletResponse
httpservletresponse)
throws ServletException, IOException
{
String s = textProducer.getText();
httpservletrequest.getSession().setAttribute
("SIMPLE_CAPCHA_SESSION_KEY", s);
DefaultCaptchaIml defaultcaptchaiml = new
DefaultCaptchaIml(props);
httpservletresponse.setHeader("Pragma", "no-
cache");
httpservletresponse.setHeader("Cache-
Control", "no-cache");
defaultcaptchaiml.createImage
(httpservletresponse.getOutputStream(), s);
}

This will prevent the cache problem.

Thanks.

Discussion

  • rinden

    rinden - 2007-02-12

    Logged In: YES
    user_id=1717301
    Originator: NO

    When will this be a part of a new release?

     
  • rinden

    rinden - 2007-02-14

    Logged In: YES
    user_id=1717301
    Originator: NO

    Thx for the posting. This was really good to know.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.