Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.sction.security.captcha;
 
 
public class CaptchaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	public CaptchaServlet() {
		super();
	}
	public static boolean validate(HttpSession sessionString captcha) {
		Object pcaptcha = session.getAttribute(session.getId() + "_captcha");
		return captcha.trim().equals(pcaptcha + "");
	}
	public static boolean validateIgnoreCase(HttpSession sessionString captcha) {
		Object pcaptcha = session.getAttribute(session.getId() + "_captcha");
		return captcha.trim().equalsIgnoreCase(pcaptcha + "");
	}
	private String captchaServiceName = "imageCaptchaService";
	public void init(ServletConfig servletConfigthrows ServletException {
		if (servletConfig.getInitParameter("captchaServiceName") != null) {
			 = servletConfig
					.getInitParameter("captchaServiceName");
		}
		super.init(servletConfig);
	}
	protected void service(HttpServletRequest request,
		try {
			ApplicationContext ctx = WebApplicationContextUtils
catch (Exception e) {
			cs.setHeight(26);
			cs.setWidth(90);
		}
		response.setContentType("image/png");
		response.setHeader("cache""no-cache");
		response.setDateHeader("Expires", 0);
		response.setHeader("Cache-Control""no-store");
		response.setHeader("Pragma""no-cache");
		HttpSession session = request.getSession(true);
		OutputStream os = response.getOutputStream();
		String patchca = EncoderHelper.getChallangeAndWriteImage(cs"png"os);
		String captchaId = session.getId() + "_captcha";
		session.setAttribute(captchaIdpatchca);
		os.flush();
		os.close();
	}
New to GrepCode? Check out our FAQ X