How to print a Struts2 ActionMessage in a JavaScript alert box

前端 未结 1 493
抹茶落季
抹茶落季 2021-01-17 01:38

I have one Action class which is sending an action message using addActionMessage();.

I want to display that message in my JSP using a Jav

1条回答
  •  迷失自我
    2021-01-17 02:07

    The tag generates an HTML like the following:

    • Your Message 1
    • Your Message 2, and so on...

    This will break your javascript function with invalid JS code:

    alert('
    • ... ');

    The solution is to manually iterate over your messages, and build the output by yourself, with , instead of using :

    
        
    
    

    Also remember to wrap the single quotes from your actionMessages.

    0 讨论(0)
提交回复
热议问题