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

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

        • <bdo id='tGhjN'></bdo><ul id='tGhjN'></ul>
      1. <legend id='tGhjN'><style id='tGhjN'><dir id='tGhjN'><q id='tGhjN'></q></dir></style></legend>

        如何使用 jQuery Ajax 将 javascript 数组发送到 struts 动作

        How to send javascript array to struts action by using jQuery Ajax(如何使用 jQuery Ajax 将 javascript 数组发送到 struts 动作)

        1. <small id='TqIRB'></small><noframes id='TqIRB'>

              <tbody id='TqIRB'></tbody>

              • <tfoot id='TqIRB'></tfoot>
                  <bdo id='TqIRB'></bdo><ul id='TqIRB'></ul>
                  <legend id='TqIRB'><style id='TqIRB'><dir id='TqIRB'><q id='TqIRB'></q></dir></style></legend>
                  <i id='TqIRB'><tr id='TqIRB'><dt id='TqIRB'><q id='TqIRB'><span id='TqIRB'><b id='TqIRB'><form id='TqIRB'><ins id='TqIRB'></ins><ul id='TqIRB'></ul><sub id='TqIRB'></sub></form><legend id='TqIRB'></legend><bdo id='TqIRB'><pre id='TqIRB'><center id='TqIRB'></center></pre></bdo></b><th id='TqIRB'></th></span></q></dt></tr></i><div id='TqIRB'><tfoot id='TqIRB'></tfoot><dl id='TqIRB'><fieldset id='TqIRB'></fieldset></dl></div>
                • 本文介绍了如何使用 jQuery Ajax 将 javascript 数组发送到 struts 动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我是 Struts 2 的新手.我想通过使用 jQuery AJAX 请求将 javascript 数组发送到 Struts 操作类.
                  警报工作正常, execute() 不工作.
                  当我将 System.out.println("language : "+ language); 放入 execute() 方法时,输出为

                  I am new to Struts 2. I want to send a javascript array to a Struts action class by using jQuery AJAX request.
                  The alert is working fine, the execute() is not working.
                  When I put System.out.println("language : "+ language); in the execute() method, the output is

                  语言:null.

                  var langArr = [];
                      $("#language").each(function()
                      {
                        var selectedLang = $("select").val();
                        var selectedValues = $(this).val();
                        langArr.push(selectedValues);
                       });
                      alert("Languages : " + langArr);
                  
                      $.ajax({
                          method: "POST",
                          url: "getProjectPost",
                          data: { "language" : langArr },
                          dataType : "json",
                          traditional: true,
                          success:
                              function()
                              {
                               alert("Success");
                              },
                          error: 
                             function()
                              {
                               alert("Error");
                              }
                      });
                  

                  这是我的动作课

                  public class ProjectPostAction {
                  
                      private int[] language;
                  
                      public final int[] getLanguage() {
                          return language;
                      }
                  
                      public final void setLanguage(int[] language) {
                          this.language = language;
                      }
                  
                      public String execute() throws Exception {          
                             System.out.println("language : "+ language[0]);
                             return "success";    
                      }
                  

                  推荐答案

                  Jquery 使用 $.param 在内部使用 $.ajax.

                  Jquery serializes data sent as parameters using $.param internally when doing ajax request with $.ajax.

                  数据应设置为整数数组或以逗号分隔的整数列表的字符串,以便 jQuery 可以在与请求一起发送之前正确序列化它.

                  The data should be set as array of integers or string with comma separated list of integers, so jQuery can correctly serialize it before sending with the request.

                  您只能使用 traditional 设置向 struts2 发送数组参数,因为 struts 使用类型转换来使用键作为参数名称来填充操作的属性.

                  You can send an array parameter to struts2 only with traditional setting because struts using type conversion to populate a property of the action using keys as parameter names.

                  因此,该数组应该是一个原始整数数组,但您的数组包含其他不是原始整数的对象.

                  为了演示你可以看这个demo来了解如何获取参数值并以与 $.ajax 相同的方式对其进行序列化.

                  To demonstrate you can see this demo to understand how to get parameter values and serialize it the same way like is doing $.ajax.

                  Struts2 还可以通过默认类型转换来转换包含逗号分隔值的字符串.例如,您可以看到复选框列表值如何传递给 struts 操作.

                  Struts2 also can convert a string containing a comma separated values by default type conversion. For example you can see how checkbox list values are passed to struts action.

                  这篇关于如何使用 jQuery Ajax 将 javascript 数组发送到 struts 动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                  <i id='Bp5mD'><tr id='Bp5mD'><dt id='Bp5mD'><q id='Bp5mD'><span id='Bp5mD'><b id='Bp5mD'><form id='Bp5mD'><ins id='Bp5mD'></ins><ul id='Bp5mD'></ul><sub id='Bp5mD'></sub></form><legend id='Bp5mD'></legend><bdo id='Bp5mD'><pre id='Bp5mD'><center id='Bp5mD'></center></pre></bdo></b><th id='Bp5mD'></th></span></q></dt></tr></i><div id='Bp5mD'><tfoot id='Bp5mD'></tfoot><dl id='Bp5mD'><fieldset id='Bp5mD'></fieldset></dl></div>
                • <small id='Bp5mD'></small><noframes id='Bp5mD'>

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

                      <tbody id='Bp5mD'></tbody>
                      <bdo id='Bp5mD'></bdo><ul id='Bp5mD'></ul>
                        <tfoot id='Bp5mD'></tfoot>