????public?ModelAndView?handleRequest(HttpServletRequest?request,?HttpServletResponse?response)?throws?Exception{??
????????//?Set?to?expire?far?in?the?past.??
????????response.setDateHeader("Expires",?0);??
????????//?Set?standard?HTTP/1.1?no-cache?headers.??
????????response.setHeader("Cache-Control",?"no-store,?no-cache,?must-revalidate");??
????????//?Set?IE?extended?HTTP/1.1?no-cache?headers?(use?addHeader).??
????????response.addHeader("Cache-Control",?"post-check=0,?pre-check=0");??
????????//?Set?standard?HTTP/1.0?no-cache?header.??
????????response.setHeader("Pragma",?"no-cache");??
??
????????//?return?a?jpeg??
????????response.setContentType("image/jpeg");??
??
????????//?create?the?text?for?the?image??
????????String?capText?=?captchaProducer.createText();??
??
????????//?store?the?text?in?the?session??
????????request.getSession().setAttribute(Constants.KAPTCHA_SESSION_KEY,?capText);??
??
????????//?create?the?image?with?the?text??
????????BufferedImage?bi?=?captchaProducer.createImage(capText);??
??
????????ServletOutputStream?out?=?response.getOutputStream();??
??
????????//?write?the?data?out??
????????ImageIO.write(bi,?"jpg",?out);??
????????try?{??
????????????out.flush();??
????????}?finally?{??
????????????out.close();??
????????}??
????????return?null;??
????}??
}??
?
3.校驗用戶輸入的Controller
?
?
Java代碼??
?
/**?
?*?ClassName:?LoginController?
?
?*?Function:?登錄Controller.?
?
?*?date:?2013-12-10?上午11:41:43?
?
?*?
?*?@author?chenzhou1025@126.com?
?*/??
@Controller??
@RequestMapping("/login")??
public?class?LoginController?{??
??
????/**?
?????*?loginCheck:ajax異步校驗登錄請求.?
?
?????*?
?????*?@author?chenzhou1025@126.com?
?????*?@param?request?
?????*?@param?username?用戶名?
?????*?@param?password?密碼?
?????*?@param?kaptchaReceived?驗證碼?
?????*?@return?校驗結果?
?????*?@since?2013-12-10?
?????*/??
????@RequestMapping(value?=?"check",?method?=?RequestMethod.POST)??
????@ResponseBody??
????public?String?loginCheck(HttpServletRequest?request,??
評論
查看更多