Well, to start off with I'd never be using a
JSP for this.
Modern best practices dictate that data processing should take place in a
servlet or classes delegated from a servlet.
That would simplify things considerably since you are just writing
Java at that point rather than dealing with JSP stuff as well.
I'd advise this refactoring.