0

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?

Zeetro_
  • 21
  • 5

1 Answers1

1

You are confusing attributes with parameters.

The message is always null in your JSP because you have set an attribute in you servlet, but in your JSP you are looking for a parameter. They are different things.

Things to do:

Bogdan
  • 23,890
  • 3
  • 69
  • 61