The error you are showing has to do with at what point the code you posted gets executed. The exception says
java.lang.IllegalStateException: Cannot forward after response has
HttpServletResponse is typically committed, ie. the headers are sent, when you start writing to its
OutputStream. At this point you cannot change the headers or status code and you cannot use a
forward() the request to another resource.
Check if you are doing any of these things.