You have a couple of forwards in your code. One example:
String url="/index.jsp";
RequestDispatcher dispatcher=getServletContext().getRequestDispatcher(url);
dispatcher.forward(request, response);
Further down the code you have a block with try/catch/finally
. Specifically you have the block
finally
{
request.setAttribute("UserData", lst);
RequestDispatcher rd=request.getRequestDispatcher("/displayrecord.jsp");
rd.forward(request, response);
lst.clear();
out.close();
}
When you forward a request it does not stop the execution in your method. Once it is done with the forward it will continue execution where you left off and you are having a guaranteed forward in the end with the finally
block. The finally
block will be executed no matter what happened earlier in your code. If you are first executing one of the forwards up in the top of your code, it will fail when you are hitting the finally
block because then it is trying to forward the request a second time and that will cause the error you are experiencing.
Look closely at your full stack trace because it should indicate the exact line number where it is trying to use the response (in your case the forwards) a second time. You need to rearrange/rewrite your code so that you only execute one forward (at most).