我使用的是jQuery 1.4.2,Struts 2.3.34和Struts JSON插件2.3.34。
在将值从网页发布到Action时,一切都很好。但是如果我向bean添加了子数组/列表,则子数组/列表在发布后变为OPTIONS /oauth/token HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Access-Control-Request-Method: POST
Origin: http://localhost:4200
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/67.0.3396.79 Safari/537.36
DNT: 1
Access-Control-Request-Headers: authorization
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
HTTP/1.1 401 Unauthorized
Server: Apache-Coyote/1.1
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
WWW-Authenticate: Basic realm="oauth2/client"
Access-Control-Allow-Origin: http://localhost:4200
Vary: Origin
Access-Control-Allow-Methods: POST
Access-Control-Allow-Headers: authorization
Access-Control-Allow-Credentials: true
Allow: GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH
Content-Length: 0
Date: Sat, 09 Jun 2018 14:19:36 GMT
。
请参阅下面的null
中的bean定义和操作映射。
BasicBean
struts.xml
SubBean.java
public class BasicBean implements Serializable {
private String partNumber;
private List<SubBean> subBeanList;
public List<SubBean> getSubBeanList() {
return subBeanList;
}
public void setSubBeanList(List<SubBean> subBeanList) {
this.subBeanList = subBeanList;
}
public String getPartNumber() {
return partNumber;
}
public void setPartNumber(String partNumber) {
this.partNumber = partNumber;
}
}
struts.xml中
public class SubBean implements Serializable {
private String maxCritical;
private String minCritical;
public String getMaxCritical() {
return maxCritical;
}
public void setMaxCritical(String maxCritical) {
this.maxCritical = maxCritical;
}
public String getMinCritical() {
return minCritical;
}
public void setMinCritical(String minCritical) {
this.minCritical = minCritical;
}
}
JQuery Ajax的JavaScript
<action name="jsTest" method="doJSon" class="com.jst.action.JSTest">
<result name="error" type="json">
<param name="includeProperties">errorResult.*</param>
</result>
<result name="success" type="json">
<param name="root">result</param>
</result>
</action>
根据调试窗口,子bean值被POST到服务器:
但它在服务器端var sbList = [];
localData = {
'"maxCritical"' : '8',
'"minCritical"' : '9'
}
sbList.push(localData);
finalData = {
'bb.partNumber':'6',
'bb.subBeanList' : sbList
}
$.ajax({
type: "post",
url: updateUrl,
data: finalData,
cache: false,
dataType: 'json',
success: function(msg){
if (msg.errorResult) {
if(msg.errorResult["error_code"] == "session_expired"){
sessionExpired();
}
return;
}
jAlert("OK");
}
});
,但其他元素Partnumber已成功发布: