比如我想在servlet里做一个清空session的操作,清空之后弹出一个提示给用户,比如“清空购物车成功!”,应该如何实现,我直接out.print();不成功... 大家帮忙解决一下,代码如下: public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { response.setContentType("text/html;utf-8");
request.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter(); HttpSession session = request.getSession();
session.setAttribute("aFood", null);
out.print("清空购物车成功!");
response.sendRedirect("index.jsp"); out.flush();
out.close();
}
throws ServletException, IOException { response.setContentType("text/html;utf-8");
request.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter(); HttpSession session = request.getSession();
session.setAttribute("aFood", null);
out.print("清空购物车成功!");
response.sendRedirect("index.jsp"); out.flush();
out.close();
}
out.print("清空购物车成功!");
response.sendRedirect("index.jsp");out.flush();
out.close();
这四句代码就没有意义了。
你要想跳转到index.jsp并且给出消息提示。
那就直接在indexjsp去做吧。
response.sendRedirect("index.jsp");
注意,关闭当前新页面前,是否需要将母页面相关信息进行相应修改呢?
response.getWriter.write(js);