That is quite a mess.
First get rid of all that Java code from JSP.
JSPs should never contain Java code. In fact your exception will probably go away as soon as you move all that Java code into servlets and helper classes.
JSPs should be used for presentation only.

Possible solutions to this problem are
1.) Make forward/redirect as early as possible before any HTML is output.
2.) Increase the buffer size. <%@ page buffer="24kb"%> default is (8kb)
3.) Put a return statement after the code

Java Code:

dispatcher.forward(request,response);

But the first and most important thing is to move all the Java code away from the JSP.