最近碰到个问题,SSH(struts2)框架已经搭配测试好了,然后在JSP页面中加入了一组radio,想把被选中的radio直接注入到action中,但是一直报错,提示JSP页面所提交的是radio.value这一组值,而不是选中的值,错误信息如下:
2009-09-18 09:46:01,859 WARN [com.opensymphony.xwork2.ognl.OgnlValueStack] - Error setting value
ognl.MethodFailedException: Method "setIsmovealert" failed for object com.aowin.form.TxbuildapplyForm@176a8c8 [java.lang.NoSuchMethodException: setIsmovealert([Ljava.lang.String;)]
......<form action="txbuildapply_addTxBuildApply.action" method="post"  name="form1" id="form1" >
      <input name="txbuildapplyForm.isOdd"  type="radio" class="radio_box" value="2" id="radio1">1
      <input name="txbuildapplyForm.isOdd" type="radio" class="radio_box"  value="0" id="radio1">0
      <input type="submit" value="submit">
</form>
public class TxbuildapplyAction {
private TxbuildapplyService txbuildapplyService;
private TxbuildapplyForm txbuildapplyForm;  
public TxbuildapplyForm getTxbuildapplyForm() {
return txbuildapplyForm;
} public void setTxbuildapplyForm(TxbuildapplyForm txbuildapplyForm) {
this.txbuildapplyForm = txbuildapplyForm;
} public TxbuildapplyService getTxbuildapplyService() {
return txbuildapplyService;
} public void setTxbuildapplyService(TxbuildapplyService txbuildapplyService) {
this.txbuildapplyService = txbuildapplyService;
}
        public String addTxBuildApply(){
                 //这里直接报错,
//txbuildapplyService.buildApplyInit(txbuildapplyForm);
//System.out.println(txbuildapplyForm.getIscust());
System.out.println(txbuildapplyForm.getIsodd());  
                


return returnFlag;

}  

解决方案 »

  1.   

    楼主,你的代码有点问题,先把GET,SET的方法写正确来再测试吧。
    txbuildapplyForm.isOdd
    txbuildapplyForm.getIsodd() 
    很明显就看出你的get方法写错了,应该是getIsOdd()
    另外根据你的错误信息
    setting value ognl.MethodFailedException: Method "setIsmovealert" failed for object com.aowin.form.TxbuildapplyForm@176a8c8,很显然,你的变量名应该是ismovealert,但是又提供错了set方法或者没有提供set方法。
    建议楼主还是用IDE直接生成GET/SET方法吧。