我为我的jsp创建了一条ajax线... Sql查询重新列出了很多列..我想在for循环中添加这些列,并且for循环工作正常,这是在ajax cors内部。但是当jsp页面加载所有值时显示为未定义。我不能客人说错误。值成功传递给jsp.I使用postman检查它并提醒msg ...
My model class is Product
import javax.persistence.*;
import javax.validation.constraints.NotNull;
@Entity
@Table(name = "products")
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "product_id")
private long productId;
@NotNull
@Column(unique = true, nullable = false)
private int serialNo;
private int slsiUnit;
private String itemDesc;
private int slsNo;
private String hsCode;
private String userId;
public long getProductId() {
return productId;
}
public void setProductId(long productId) {
this.productId = productId;
}
public int getSerialNo() {
return serialNo;
}
public void setSerialNo(int serialNo) {
this.serialNo = serialNo;
}
public int getSlsiUnit() {
return slsiUnit;
}
public void setSlsiUnit(int slsiUnit) {
this.slsiUnit = slsiUnit;
}
public String getItemDesc() {
return itemDesc;
}
public void setItemDesc(String itemDesc) {
this.itemDesc = itemDesc;
}
public int getSlsNo() {
return slsNo;
}
public void setSlsNo(int slsNo) {
this.slsNo = slsNo;
}
public String getHsCode() {
return hsCode;
}
public void setHsCode(String hsCode) {
this.hsCode = hsCode;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("Product{");
sb.append("serialNo=").append(serialNo);
sb.append(", slsiUnit=").append(slsiUnit);
sb.append(", itemDesc='").append(itemDesc).append('\'');
sb.append(", slsNo=").append(slsNo);
sb.append(", hsCode='").append(hsCode).append('\'');
sb.append(", userId='").append(userId).append('\'');
sb.append('}');
return sb.toString();
}
}
ajax cord是
<script>
$(document).ready(function () {
$.ajax({
type: 'GET',
url: '${pageContext.request.contextPath}/restservice/ViewProduct',
success: function (result) {
var jString = JSON.stringify(result);
var jdata = JSON.parse(jString);
alert(jString);
for (var x = 0; x < jdata.length; x++) {
var tr = "<tr>";
var td1 = "<td>" + jdata.itemDesc + "</td>";
var td2 = "<td>" + jdata.itemDesc + "</td>";
var td3 = "<td>" + jdata.serialNo + "</td>";
var td4 = "<td>" + jdata.serialNo + "</td>";
var td5 = "<td>" + jdata.serialNo + "</td></tr>";
$("#example2").append(tr + td1 + td2 + td3 + td4 + td5);
}
}
});
});
</script>
当我在JSP上的jString添加警报时,所有值视图都成功。我想将这些值映射到表
请帮帮我。