public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { Member member = (Member) RequestUtil.parseRequestToObject(request,Member.class); if (member == null) { jzLogic.insertMember(member); return new ModelAndView("index"); } else { return new ModelAndView("Error", "message", "账号已被注册!"); } }
在上述代码中如果需要使用out.print打印如alert("");信息可按以下方式进行:
...... response.setContentType("text/html; charset=gbk"); PrintWriter out = response.getWriter(); out.println("<script language='javascript'>"); out.println("alert('账号已被注册!');"); out.println("history.back();"); out.print("</script>"); return null; ......
return null,如果return new ModelAndView则直接转发