This kind of java.lang.IllegalStateException exception are triggered when some Java code is executed after a forward(), sendRedirect() or sendError(). You can refer to this StackOverflow thread to learn…