I’m writing to the browser window using servletResponse.getWriter().write(String).
But how do I clear the text which was written previously by some other similar write call?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The short answer is, you cannot — once the browser receives the response, there is no way to take it back. (Unless there is some way to abnormally stop a HTTP response to cause the client to reload the page, or something to that extent.)
Probably the last place a response can be “cleared” in a sense, is using the
ServletResponse.resetmethod, which according to the Servlet Specification, will reset the buffer of the servlet’s response.However, this method also seems to have a catch, as it will only work if the buffer has not been committed (i.e. sent to the client) by the
ServletOutputStream‘sflushmethod.