<legend id='EqAIz'><style id='EqAIz'><dir id='EqAIz'><q id='EqAIz'></q></dir></style></legend>

      <small id='EqAIz'></small><noframes id='EqAIz'>

        <i id='EqAIz'><tr id='EqAIz'><dt id='EqAIz'><q id='EqAIz'><span id='EqAIz'><b id='EqAIz'><form id='EqAIz'><ins id='EqAIz'></ins><ul id='EqAIz'></ul><sub id='EqAIz'></sub></form><legend id='EqAIz'></legend><bdo id='EqAIz'><pre id='EqAIz'><center id='EqAIz'></center></pre></bdo></b><th id='EqAIz'></th></span></q></dt></tr></i><div id='EqAIz'><tfoot id='EqAIz'></tfoot><dl id='EqAIz'><fieldset id='EqAIz'></fieldset></dl></div>
      1. <tfoot id='EqAIz'></tfoot>
        • <bdo id='EqAIz'></bdo><ul id='EqAIz'></ul>

        如何在 JavaScript 警告框中打印 Struts2 ActionMessage

        时间:2023-10-15
              1. <small id='OJb7x'></small><noframes id='OJb7x'>

                <tfoot id='OJb7x'></tfoot>
                <i id='OJb7x'><tr id='OJb7x'><dt id='OJb7x'><q id='OJb7x'><span id='OJb7x'><b id='OJb7x'><form id='OJb7x'><ins id='OJb7x'></ins><ul id='OJb7x'></ul><sub id='OJb7x'></sub></form><legend id='OJb7x'></legend><bdo id='OJb7x'><pre id='OJb7x'><center id='OJb7x'></center></pre></bdo></b><th id='OJb7x'></th></span></q></dt></tr></i><div id='OJb7x'><tfoot id='OJb7x'></tfoot><dl id='OJb7x'><fieldset id='OJb7x'></fieldset></dl></div>

                  <tbody id='OJb7x'></tbody>
              2. <legend id='OJb7x'><style id='OJb7x'><dir id='OJb7x'><q id='OJb7x'></q></dir></style></legend>
                  <bdo id='OJb7x'></bdo><ul id='OJb7x'></ul>
                  本文介绍了如何在 JavaScript 警告框中打印 Struts2 ActionMessage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 Action 类,它使用 addActionMessage(); 发送动作消息.

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

                  我想使用 JavaScript 警告框在我的 JSP 中显示该消息.

                  I want to display that message in my JSP using a JavaScript alert box.

                  我试过了

                  alert  ('<s:actionmessage/>');
                  

                  但它显示的是未终止的字符串文字.

                  推荐答案

                  <s:actionmessage/> 标签 生成 HTML,如下所示:

                  <ul class="actionMessage">
                      <li>
                          <span>
                              Your Message 1
                          </span>
                      </li>
                      <li>
                          <span>
                              Your Message 2, and so on...
                          </span>
                      </li>
                  </ul>
                  

                  这将使用无效的 JS 代码破坏您的 javascript 函数:

                  This will break your javascript function with invalid JS code:

                  alert('<ul class="actionMessage">
                          <li>
                        ... 
                       ');
                  

                  解决方案是手动迭代您的消息,并自己构建输出,使用 <s:property/>,而不是使用 <s:actionmessage/>:

                  The solution is to manually iterate over your messages, and build the output by yourself, with <s:property/>, instead of using <s:actionmessage/>:

                  <s:if test="actionMessages!=null && actionMessages.size > 0">
                      <script>
                          var actionMessages;
                          <s:iterator value="actionMessages" >
                              // Iterate the messages, and build the JS String
                              actionMessages += '-' + '<s:property />' + '
                  ';
                          </s:iterator>        
                          alert (actionMessages);
                      </script>
                  </s:if>
                  

                  还记得将 actionMessages 中的单引号括起来.

                  Also remember to wrap the single quotes from your actionMessages.

                  这篇关于如何在 JavaScript 警告框中打印 Struts2 ActionMessage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 Struts 2 中验证文件上传 下一篇:如何访问 Struts 标签中的迭代器变量?

                  相关文章

                  • <bdo id='R1q1F'></bdo><ul id='R1q1F'></ul>

                  1. <tfoot id='R1q1F'></tfoot>

                    <small id='R1q1F'></small><noframes id='R1q1F'>

                      <i id='R1q1F'><tr id='R1q1F'><dt id='R1q1F'><q id='R1q1F'><span id='R1q1F'><b id='R1q1F'><form id='R1q1F'><ins id='R1q1F'></ins><ul id='R1q1F'></ul><sub id='R1q1F'></sub></form><legend id='R1q1F'></legend><bdo id='R1q1F'><pre id='R1q1F'><center id='R1q1F'></center></pre></bdo></b><th id='R1q1F'></th></span></q></dt></tr></i><div id='R1q1F'><tfoot id='R1q1F'></tfoot><dl id='R1q1F'><fieldset id='R1q1F'></fieldset></dl></div>

                      <legend id='R1q1F'><style id='R1q1F'><dir id='R1q1F'><q id='R1q1F'></q></dir></style></legend>