How to display success message in Struts?

we could display errors in Struts by executing actionErrors.add (key, new Actionmessage ("string")), addErrors (request, actionErrors); and then output it to the JSP page through

I am wondering how do I display success messages in Struts? How do you usually / usually do this?

+3
source share
2 answers

In Struts 1, you can use ActionMessage instances to represent the message that will be displayed on the JSP

ActionMessages messages = new ActionMessages();
messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message1");
messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message2");
saveMessages(request, messages); // storing messages as request attributes

"message1" and "message2" are keys for the resource property file. Very similar to handling an ActionError

JSP , "message"

<logic:messagesPresent message="true">
   <html:messages id="message" message="true">
     <bean:write name="message"/><br/>
   </html:messages>
</logic:messagesPresent>

. ,

ActionMessages messages = new ActionMessages();
messages.add("appMessage", new ActionMessage("message1");
saveMessages(request, messages); // storing messages as request attributes

"appMessage". , JSTL Struts JSP,

, .

saveMessages(request.getSession(), messages); // storing messages as request attributes

, , , .

+10

Source: https://habr.com/ru/post/1705793/


All Articles