Simple Captcha
Brought to you by:
jchilders235
Hey I found a bug in your project. In SimpleCaptchaServlet, you have to swap the last two line. You need to create your session before sending the picture :
req.getSession().setAttribute(NAME, captcha);
CaptchaServletUtil.writeImage(resp, captcha.getImage());
You didn't make the mistake for the ChineseCaptchaServlet and the Sticky one...
But great job, your project is very useful !
Does this really make any difference? I tested the current code and it seems to work fine unless I'm missing something...
It doesn't work fine...!!!
I tested it with Tomcat v6, and java throwed me an java.lang.IllegalStateException : not possible to create a session after the reponse has been send...
Then I swaped the two lines, as I explained above.
This really makes a difference, because without that, the server doesn't send a JSESSIONID to the client !!!
"""CaptchaServletUtil.writeImage(resp, captcha.getImage()); """ sends data to the client,
but your web server needs to be aware that you want to send these datas with a jsession id.
The only solution, is to write req.getSession().setAttribute(NAME, captcha); before sending datas.
Ok, fair enough. What version of Tomcat are you using? I'm using Tomcat 6.0.14 and I do not see this issue.
I'm using Tomcat 6.0.18 (on Windows)
I think it's because the following Tomcat-bug
https://wiki.apache.org/tomcat/FAQ/KnownIssues#ImageIOIssues
The swap of the two lines was sufficient for me.