public String regist(String varifyCode, String uname , String pwd , String email, HttpSession session, HttpServletResponse response) throws IOException {
Object kaptchaCodeObj = session.getAttribute("KAPTCHA_SESSION_KEY");
if (kaptchaCodeObj == null || !varifyCode.equals(kaptchaCodeObj)){
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
PrintWriter out = response.getWriter();
out.println("<script language='javascript'>alert('验证码不正确!');window.location.href='page.do?operate=page&page=user/regist'</script>");
}
userService.regist(new User(uname, pwd, email, 0));
return "user/login";
}
UserController 中的 regist 方法
如果注册失败,由后端向页面返回弹窗和重新回到注册页面
后端能写 script 并展示在前端页面,通过 response 带回 script 标签
标签:String,实现,kaptchaCodeObj,regist,page,注册,response,书城,页面 From: https://www.cnblogs.com/Ashen-/p/17079897.html