在用myeclipse做毕业设计的时候,我想要在jsp页面向action跳转的时候,传数据id的值到action里,再用域模型接收。jsp里面的id有值,但是action里面获取id的那一行会报错:空指针异常;查找了好久发现是我在action里面定义的域模型对象的变量名无法生成get方法,只能生成set方法,具体为什么我也不知道,还希望高手可以指点。把变量名改一下,再生成get、set方法就可以了。下面是我的例子。
jsp页面:
<td style="text-align: center">
<a id="add_dialog" href="MyEngLearn/frame/getWelnews.action?welnews.id=${wn.id}">查看精彩内容</a>
</td>
action页面:
private Welnews welnews;
public void setWelnews(Welnews welnews) {
this.welnews = welnews;
}
public String getWelnews()
{
int id=welnews.getId();
Welnews wn=welnewsservice.getWelnewsById(id);
this.put2Session("wn", wn);
return "getWelnews";
}
welnews对象不能生成get方法,因而域模型不起作用,得不到前台传来的id值。把welnews改成welnew就,再生成get、set方法就可以了。
jsp页面:
<td style="text-align: center">
<a id="add_dialog" href="MyEngLearn/frame/getWelnews.action?welnew.id=${wn.id}">查看精彩内容</a>
</td>
action页面:
private Welnews welnew;
public Welnews getWelnew() {
return welnew;
}
public void setWelnew(Welnews welnew) {
this.welnew = welnew;
}
public String templateFrame()
{
PageModel<Welnews> pm=welnewsservice.ListWelnews(pageNo, pageSize);
this.put2Session("recordCount", pm.getRecordCount());
this.put2Session("pageNo", pm.getPageNo());
this.put2Session("pageSize", pm.getPageSize());
this.put2Session("data", pm.getData());
return "template";
}