servlet输出提示
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println(" ");
out.println("
out.flush();
out.close();
request.getRequestDispatcher("bill.jsp");
}
这是servlet的dopost()方法,这样是可以的,我试了
后台
request.setAttribute("msg", "保存成功");
前台,用jstl
在转发之前内存中不能输出任何东西,不然会报错
Servlet代码如下:
request.setAttribute("rs", "修改成功");
this.getServletContext().getRequestDispatcher("/bill.jsp").forward(request, response);
前台代码:
<%=request.getAttribute("rs") == null ? "" : request.getAttribute("rs") %>
最好用异步实现
ajax
标签:servlet,输出,提示