【开源中国 APP 全新上线】“动弹” 回归、集成大模型对话、畅读技术报告”
新人想问下 关于Struts2框架的web项目的传值问题
网页代码
function updateCustomerType(id,type){
$.ajax({
url : "<%=contextPath%>/cus/abnormalCus!updateCoustmoerType.action",
data : {
"customer.cusId" : id,
"customer.customerType" : type
},
type : "post",
cache : false,
async : false,
success : function(result) {
window.location.reload();
},
error : function(error) {
//alert(error);
}
});
}
实现代码
private CustomerUpdateTypeDTO customerUpdateTypeDTO;
/** 修改用户级别 */
public String updateCoustmoerType() {try {
iCustomer.updateType(customerUpdateTypeDTO);
} catch (Exception e) {
logger.error("AbnormalCustomerAction.updateCoustmoerType", e);
return ERROR;
}
return null;
}
public CustomerUpdateTypeDTO getCustomerUpdateTypeDTO() {
return customerUpdateTypeDTO;
}
public void setCustomerUpdateTypeDTO(CustomerUpdateTypeDTO customerUpdateTypeDTO) {
this.customerUpdateTypeDTO = customerUpdateTypeDTO;
}
实体代码
public class CustomerUpdateTypeDTO implements Serializable{
private static final long serialVersionUID = 1L;
private Integer cusId;
private Integer customerType;
public Integer getCusId(){
return cusId;
}
public void setCusId(Integer cusId){
this.cusId = cusId;
}
public int getCustomerType() {
return customerType;
}
public void setCustomerType(Integer customerType) {
this.customerType = customerType;
}
}
报错
[WARN]-17:51:01-OgnlValueStack - Error setting expression 'customer.customerType' with value '[Ljava.lang.String;@54218eec'
ognl.OgnlException: target is null for setProperty(null, "customerType", [Ljava.lang.String;@54218eec)
at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2326)
at ognl.ASTProperty.setValueBody(ASTProperty.java:127)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
at ognl.SimpleNode.setValue(SimpleNode.java:301)
at ognl.ASTChain.setValueBody(ASTChain.java:227)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
at ognl.SimpleNode.setValue(SimpleNode.java:301)
at ognl.Ognl.setValue(Ognl.java:737)
at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:234)
我一开始int 类型 出的这个问题 网上找了找好像是什么类型不对的问题 然后看到有人改成Integer 但是我改了后还是不行 求各位大神帮忙看看 任务期限快到了 卡在这里一天了!!
应该是你ajax这里写的有问题,
而且该用OGNL表达式的用表达式写。action没贴出来没法具体分析
1 发代码请格式化
2 发action类代码