我的代码为:public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setCharacterEncoding("GBK");
PrintWriter out = response.getWriter();
if (!validator.equals(in_validateCode)){
out.println(" <script type=\"text/javascript\"> ");
out.println(" alert('验证码填写错误!') ");
out.println(" </script> ");
out.flush();
out.close();
response.sendRedirect("../index.jsp");
}}其中:out.flush(); out.close(); 和 response.sendRedirect("../index.jsp"); 好像不能同时使用,有
java.lang.IllegalStateException: Response already committed
异常抛出但我在帮助文档中没有找到那里出的问题.请大家帮我指出问题所在,谢谢!!!!!
throws ServletException, IOException {
response.setCharacterEncoding("GBK");
PrintWriter out = response.getWriter();
if (!validator.equals(in_validateCode)){
out.println(" <script type=\"text/javascript\"> ");
out.println(" alert('验证码填写错误!') ");
out.println(" </script> ");
out.flush();
out.close();
response.sendRedirect("../index.jsp");
}}其中:out.flush(); out.close(); 和 response.sendRedirect("../index.jsp"); 好像不能同时使用,有
java.lang.IllegalStateException: Response already committed
异常抛出但我在帮助文档中没有找到那里出的问题.请大家帮我指出问题所在,谢谢!!!!!
request.getRequestDispatcher("/index.jsp").forward(request, response);
request.getRequestDispatcher("/index.jsp").forward(request, response);
可以完成跳转,但 alert('验证码填写错误') 没有看到!2楼,在我这里测试显示如果在 out.flush(); out.close(); 后面使用,就会有异常 java.lang.IllegalStateException: Cannot forward a response that is already committed 抛出如果在 out.flush(); out.close(); 前面使用,和 3楼 的问题一样,没有看到 alert('验证码填写错误')辛苦大家了, 谢谢 !!!!!!!
out.print( "alert( '提交成功 '); ");
out.print( "window.location.href= '/XXX/yyy.jsp?aaa=78'; ");
out.print( " </script> ");
或者直接用ajax吧
不用打印js代码了
response.sendRedirect("../index.jsp");