@RequestMapping(value="/check", method=RequestMethod.POST)
public String check(ServletRequest theRequest, ServletResponse theResponse) {
HttpServletRequest request = (HttpServletRequest) theRequest;
HttpServletResponse response = (HttpServletResponse) theResponse;
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
CaptchaService captchaService = (CaptchaService) context.getBean("captchaService");
try {
String captchaID = request.getSession().getId();
logger.info("captchaID:"+captchaID);
String challengeResponse = request.getParameter("j_captcha");
logger.info("challengeResponse:"+challengeResponse);
boolean bRet = captchaService.validateResponseForID(captchaID, challengeResponse);
if( bRet )
return "home";
else
return "login";
} catch (CaptchaServiceException e) {
logger.error(e.getMessage(), e);
return "login";
}
}
public String check(ServletRequest theRequest, ServletResponse theResponse) {
HttpServletRequest request = (HttpServletRequest) theRequest;
HttpServletResponse response = (HttpServletResponse) theResponse;
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
CaptchaService captchaService = (CaptchaService) context.getBean("captchaService");
try {
String captchaID = request.getSession().getId();
logger.info("captchaID:"+captchaID);
String challengeResponse = request.getParameter("j_captcha");
logger.info("challengeResponse:"+challengeResponse);
boolean bRet = captchaService.validateResponseForID(captchaID, challengeResponse);
if( bRet )
return "home";
else
return "login";
} catch (CaptchaServiceException e) {
logger.error(e.getMessage(), e);
return "login";
}
}
本文详细介绍了如何使用Spring MVC实现POST请求处理,通过获取并验证用户输入的验证码信息来确保用户身份的有效性。

3916

被折叠的 条评论
为什么被折叠?



