How can I feed a CAPTCHA image into the servlet page output?
The difficulty you are facing is that Web browsers see your servlet output as a single HTTP response stream, which is either an HTML document or an image or some other content item. It is not possible to encode the CAPTCHA image content inline into the HTML markup, the HTML img element requires a reference to an image at a separate URL source. The typical request sequence for a CAPTCHA form page would be: • Request CAPTCHA form page (servlet) • Download CAPTCHA form page HTML with image reference • Request CAPTCHA image (servlet) • Download CAPTCHA image as part of the main page load • Submit CAPTCHA form with image reference and human input (servlet) • Servlet checks CAPTCHA image content with human input and sends response • Download HTML success or error page output accordingly It is critical the HTML page, form and image reference must not indicate the “decoded” contents of the CAPTCHA image. But the servlet that checks the CAPTCHA must know the decoded contents and the human input