Controller A shows some data and displays a form.
The form submits to Controller B.
When form errors are found in Controller B, the form needs to be re-displayed by Controller A.
To do this requires a return redirect "blah"
in Controller A.
To pass the errors back to Controller A using a redirect, I can set the error message in the model:
model.put("errormsg", "look what happened");
This has the annoying effect of putting the entire text of the error message into the URL:
/controllera/somemethod?errormsg=look+what+happened
However, even though I see the text on the URL, when I try to display it from the JSTL, nothing is shown:
<c:out value="${errormsg}"/>
Is there a better approach to all of this?
IMHO better approach is to use standard scheme: controller A shows form, data submitted to controller A and if error occurs controller A display errors. If data valid controller A do redirect to controller B.
I'd recommend:
req.setAttribute("errormsg", "look what happened");
The JSTL output should work just fine then.
Place this on your JSP: