For context I have a jsp called "withdraw.jsp" that calls a servlet that processes a withdrawal. In this servlet I would like to pass a string message if the transaction is successful or not and I would like to send this message to the same jsp that called the servlet (which is still "withdraw.jsp". Here is what I did so far
//In the servlet
RequestDispatcher view = request.getRequestDispatcher("registeredUser/withdraw.jsp");
String error = (String)ex.getMessage();
request.setAttribute("errorMessage", error);
view.include(request,response); // i also tried forward here
//In the jsp
<% if(request.getParameter("errorMessage") != null){ %>
<p> <%=(String)request.getParameter("errorMessage")%> </p>
<% } %>
If I run this code, the jsp wouldn't retrieve the errorMessage since it is null despite being set as an attribute by the servlet. Any help?