I have the following code snippet in my web app:
if (request.getParameter("user").equals("luke")||session == null && !(uri.endsWith("html") || uri.endsWith("LoginServlet"))) {
System.out.println("<<<----------denied------------->>>>");
pw.println("zzzzzzzzzz");
this.context.log("Unauthorized access request");
pw.flush();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//res.sendRedirect("login.html");
req.getRequestDispatcher("login.html").include(request,response);
}
When I am using flush before Forward(), it's throwing IllegalStateException
(since the response is sent the moment we call flush and later we are trying to resend the response using forward) but the code works fine even after I provided flush before the rd.include()
. Why doesn't it throw the exception here?
TIA