晚上好,我想知道如何清除写入 PrintWriter 的数据,即是否可以在打印后从 PrintWriter 中删除数据?
在这个 servlet 中,我将一些文本打印到响应中,并在 # 表示的行处,我想删除所有以前打印的数据并打印新的东西:
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
String uName = request.getParameter("uName");
String uPassword = request.getParameter("uPassword");
if (uName .equals("Islam")) {
out.println("Valid-Name");
if (uPassword !=null) {
if (uPassword .equals("Islam")) {
// # clear the writer from any printed data here
out.println("Valid-password");
} else {
out.println("");
out.println("InValid-password");
}
}
} else {
out.println("InValid-Name");
}
}
注意:我尝试了 out.flush() 但旧的打印文本仍然存在