As Bear and Paul mentioned you would need refractor your code pretty much.
For every http request,
- the servlet container creates a request and response objects.
- your servlet uses the data in the request to process
- it sets back necessary data in the response object
- the Servlet container based on your page forward responds back as a jsp
At this last step when the response leaves your container, your outputstream will be committed and you cannot modify it later.
Here you are trying to modify the committed response in your result jsp which will throw you a response saying outputstream is already committed