2016-09-19 74 views
-1

我有问题Struts Action类要发送的由支柱迭代器遍历一个数组通过Ajax调用以及如何接收在Struts Action类Struts Action类的单个阵列的动态数据如何发送阵列通过AJAX

这里是我的示例代码:

支柱迭代

<table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example3"> 
    <thead> 
    <tr> 
    <th><a href="#" id="selectall">Select all</a></th> 
    <th>Student Name</th> 
    <th>Phone</th> 
    <th>Email</th> 
    <th>ReferenceId</th> 
    </tr> 
    </thead> 
    <tbody> 
    <s:iterator value="adminSms"> 
    <tr> 
    <td><s:checkbox name="refIDS" cssClass="case" fieldValue="%{ref}" /></td> 
    <td><s:property value="studentname" /></td> 
    <td id="phone"><s:property value="phone" /></td> 
    <td id="email"><s:property value="email" /></td> 
    <td><s:property value="ref" /></td> 
    </tr> 
    </s:iterator> 
    </tbody> 
    </table> 

Ajax调用

$(document).ready(function() { 
      $('Send').click(function() { 
       var Data = { 
        phone : $('#phone').val(), 
        email : $('#email').val() 
       } 
       $.ajax({ 
        type : 'POST', 
        url : 'myURL', 
        data : JSON.stringify(Data) 
       }); 
      }); 
     }); 

Action类

public class MyActionClass extends ActionSupport { 

    private String [] phoneNumbers; 
    private String [] emails; 

    public String[] getPhoneNumbers() { 
     return phoneNumbers; 
    } 

    public void setPhoneNumbers(String[] phoneNumbers) { 
     this.phoneNumbers = phoneNumbers; 
    } 

    public String[] getEmails() { 
     return emails; 
    } 

    public void setEmails(String[] emails) { 
     this.emails = emails; 
    } 

    @Override 
    public String execute() throws Exception { 
     for (int i = 0; i < emails.length; i++) { 
      System.out.println(emails[i]); 
     } 
     for (int i = 0; i < phoneNumbers.length; i++) { 
      System.out.println(phoneNumbers[i]); 
     } 
     return SUCCESS; 
    } 
} 
+0

您可以通过Ajax发送。 –

+0

只发送id并检索对象。 –

+0

'$('Send')'中的'Send'是什么?你想达到什么目的?为什么不发送唯一的ID? –

回答

-1

在这里,在下面的代码发送两个字段值我连接两个字段值fieldValue方法属性

<s:iterator value="adminSms"> 
<tr> 
<td><s:checkbox name="emails" cssClass="case" fieldValue="%{phone+'@'+email}" /></td> 
<td><s:property value="studentname" /></td> 
<td id="phone"><s:property value="phone" /></td> 
<td id="email"><s:property value="email" /></td> 
<td><s:property value="ref" /></td> 
</tr> 
</s:iterator> 
+0

这是错的。它不映射struts属性。 –

+0

@RomanC在@符号之间同时收到电子邮件和电话数据。当涉及到行动我使用拆分功能,使独立阵列 –

+0

它只是表达式,映射数据应该是双向的。 –