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

<small id='4hRKm'></small><noframes id='4hRKm'>

  • <legend id='4hRKm'><style id='4hRKm'><dir id='4hRKm'><q id='4hRKm'></q></dir></style></legend>
      <bdo id='4hRKm'></bdo><ul id='4hRKm'></ul>
  • <tfoot id='4hRKm'></tfoot>

      1. 如何通过 POST (Ajax) 发送 JSON 数据并从 Struts 2 操作接收 JSON 响应

        How to send JSON data via POST (Ajax) and receive JSON response from Struts 2 action(如何通过 POST (Ajax) 发送 JSON 数据并从 Struts 2 操作接收 JSON 响应)
          <bdo id='3rckR'></bdo><ul id='3rckR'></ul>

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

              <small id='3rckR'></small><noframes id='3rckR'>

              <legend id='3rckR'><style id='3rckR'><dir id='3rckR'><q id='3rckR'></q></dir></style></legend>
            • <tfoot id='3rckR'></tfoot>

                  本文介绍了如何通过 POST (Ajax) 发送 JSON 数据并从 Struts 2 操作接收 JSON 响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我试图了解如何使用 JSON,并且在此过程中我试图从 Struts2 操作中获取 JSON 响应并显示响应警报.为此,我在 JavaScript 中使用 Ajax POST,如下所示:

                  I am trying to understand how to use JSON and in the process I'm trying to get a JSON response from Struts2 action and display an alert for the response. For this I'm using Ajax POST in JavaScript as follows:

                  function checkButtonClick(id){  
                  
                          var btnSave = 'saveAttendees';  
                              var atNameList = $('#attName'+id).val();
                              var ptNameList = $('#postName'+id).val();
                              var aId = $('#at_id'+id).val();
                              
                              alert("here");
                              var arr = {buttonName:  btnSave,
                                      attendeesNameList: atNameList,
                                      attendeesPostList: ptNameList,              
                                      hidden_At_id: aId
                                      };
                              $.ajax({                            
                                  data: arr,
                                  type: 'POST',
                                  dataType: 'json',               
                                  url:"meeting_record_form",
                                  
                                  success:function(result){
                                      alert(result.myMsg);
                                },
                                  error:function(result){
                                      alert("error");
                                }
                              });
                  }
                  

                  我的 Action 类包含一个 String 字段,我试图在警报中显示为 JSON 响应.但我发现这样做有问题.我错过了什么或做错了什么?

                  My Action class contains a String field that I'm trying to display in alert as JSON response. But I'm finding problem doing this. What am I missing or doing wrong?

                  我的动作类如下:

                  private String myMsg;
                  
                      public String getMyMsg() {
                          return myMsg;
                      }
                  
                      public void setMyMsg(String myMsg) {
                          this.myMsg = myMsg;
                      }
                  
                  private String updateAttendeesRecord() {
                          
                          
                          meetingRecordService.updateAttendeesRecord(attendeesListMethod(), meeting_record);
                          setMyMsg("Update Successful!");
                              return SUCCESS;
                      }
                  

                  struts.xml 文件:

                  struts.xml file:

                   <package name="default" extends="struts-default, json-default">
                      <result-types>
                        <result-type name="json" class="org.apache.struts2.json.JSONResult" />
                      </result-types>
                      <interceptors>
                        <interceptor name="json" class="org.apache.struts2.json.JSONInterceptor" />
                      </interceptors>
                      
                      <action name="meeting_record_form" class="com.task.action.MeetingRecordAction" method="updateAttendeesRecord">
                       <result name="success" type="json" />
                      </action>
                  </package>
                  

                  我的 pom.xml:

                  <dependency>
                      <groupId>org.apache.struts</groupId>
                      <artifactId>struts2-json-plugin</artifactId>
                      <version>2.3.15</version>
                  </dependency>
                  

                  推荐答案

                  我通过在 json 结果上添加 myMsg 解决了我的问题.感谢大家的帮助

                  I've solved my problem by adding myMsg on the json result. Thanks for all the help

                  这篇关于如何通过 POST (Ajax) 发送 JSON 数据并从 Struts 2 操作接收 JSON 响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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='IHno2'><tr id='IHno2'><dt id='IHno2'><q id='IHno2'><span id='IHno2'><b id='IHno2'><form id='IHno2'><ins id='IHno2'></ins><ul id='IHno2'></ul><sub id='IHno2'></sub></form><legend id='IHno2'></legend><bdo id='IHno2'><pre id='IHno2'><center id='IHno2'></center></pre></bdo></b><th id='IHno2'></th></span></q></dt></tr></i><div id='IHno2'><tfoot id='IHno2'></tfoot><dl id='IHno2'><fieldset id='IHno2'></fieldset></dl></div>

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

                      <tfoot id='IHno2'></tfoot>
                        <tbody id='IHno2'></tbody>

                        <legend id='IHno2'><style id='IHno2'><dir id='IHno2'><q id='IHno2'></q></dir></style></legend>
                        • <bdo id='IHno2'></bdo><ul id='IHno2'></ul>