I had a problem today when developing a login system to learn struts. How to transfer easily the error and messages from action, and show them on jsp pages.
It seems Struts 2’s ActionError and ActionMessage class is the a very good choice.
So in my login action, I just call directly addActionMessage()
and addActionError()
to add the messages I want:
In info.jsp:
Obviously, hasActionMessages()
here will return true when we called addActionMessages()
in our action. If it’s true, all contents in s:if
will be shown. s:actionmessage
will be replaced by the messages we just set in action.
In login.jsp:
So it’s the same. hasActionErrors()
will return true when we called addActionError()
in our action. If it’s true, all contents in s:if
will be shown. s:actionerror
will be replaced by the messages we just set in action.