Struts2中Could not create and/or set value back on to object的解决办法
来源:互联网 发布:找数据哪些网站好 编辑:程序博客网 时间:2024/04/30 03:05
反射机制依赖类的无参构造方法,这是熟悉反射机制的朋友都知道的一个常识.
但即使你深刻的理解这点,也并不意味着你在这方面不出错.
- 例子: struts2下的一个异常简单的POJO bean
public class TestBean {
private String content;
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}在前端用struts2里的freemarker 调用它, 直接调用bean属性,这应该属于struts2 的model driven技术
${testBean.id}
${testBean.content}
- 出于项目上的考虑,为POJO bean,加了一个带id的构造方法,问题就出来了
public TestBean(Long id) {
super();
this.id = id;
}
private String content;
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}struts2 开始报错:
Could not create and/or set value back on to object
- 原因:
反射机制要求用户类必须要有无参构造方法
当一个类没有构造方法时,java缺省为其加一个无参构造方法
当你为一个类添加构造方法时,实际上就禁掉了java缺省为类添加无参构造方法这个动作.
也就是说当你为类添加构造方法后,你的类实际上就没有无参构造方法了,也就不支持反射机制了
- 解决:为类手工添加无参构造方法
public TestBean(Long id) {
super();
this.id = id;
}
public TestBean() {
}
private String content;
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
0 0
- Struts2中Could not create and/or set value back on to object的解决办法
- struts2.x 的提交表单出现 Could not create and/or set value back on to object
- 六、ERROR - Could not create and/or set value back on to object
- java异常:Could not create and/or set value back on to object 总结
- webwork提交表单时的webwork Could not create and/or set value back on to object异常
- hive问题Cannot get a connection, pool error Could not create a validated object 的解决办法
- could not find object错误的解决办法
- 我遇到的Object reference not set to an instance of an object.错误的解决办法
- AFNetworking 关于JSON text did not start with array or object and option to allow fragments not set
- AFNetworking 报错 JSON text did not start with array or object and option to allow fragments not set
- silverlight项目出现object reference not set to an instance of an object的解决办法
- Struts2 could not find action or result 解决办法
- 安装VMware出现Error 1406:could not write value installpath to key的解决办法
- android studio提示failed to create jvm和could not reserve enough space for object heap的解决方法
- could not be set to a 'string' value. You must set this property to a non-null value of type
- struts2中Could not find action or result错误
- struts2中报“ Could not find action or result”
- Struts2的配置中:Could not find action or result 问题的解决方法
- iOS FMDB的一些基本操作小结
- IOS网络编程浅析
- 从程序员到技术总监,分享10年开发经验
- html的文档类型DTD
- Centos下安装配置nfs服务实现服务器间文件共享
- Struts2中Could not create and/or set value back on to object的解决办法
- 自己动手写shell命令之more
- ORACLE多表查询优化
- HDU 2212 DFS(水题)
- Ubuntu下单机伪分布式的hadoop-1.2.1稳定版的配置
- JSTL C标签 <c:if>判断参数是否为空
- 使用 CXF 做 webservice
- jQuery的性能优化
- 上传文件至ftp