Unexpected Exception caught setting 'age'-Error setting expression 'age' with value ['3']

来源:互联网 发布:mmd怎么制作动作数据 编辑:程序博客网 时间:2024/06/08 15:01
这是web页面输入框:


js中获取输入的年龄数据:
    var $btn = $("input.btn");//获取按钮元素
             //给按钮绑定点击事件
            $btn.bind("click",function(){
                $.ajax({
                    type:"post",
                    url:"simpleton/excuteAjaxJsonAjaxAction",//处理ajax请求的action,excuteAjax为处理方法名,JsonAction为action名
                  data:{//设置数据源
                        age:$("input[name=age]").val()       //注意不能有分号哦                
                    },

                    dataType:"json",//设置需要返回的数据类型
                    success:function(data){
                        var d = eval("("+data+")");//将数据转换成json类型                         
                        $("#s_age").text(""+d.age+"");                     
                    },
                    error:function(){
                        alert("系统异常,请稍后重试!");
                    }
                });
            });


strust.xml配置信息:

 <package name="simpleton" namespace = "/simpleton" extends="json-default">         
        <action name="*JsonAjaxAction" method="{1}"class="testaction.JsonAjaxAction">                    <!--结合前面url为url:"simpleton/excuteAjaxJsonAjaxAction",所以后台action类中必须有方法excuteAjax,这个错隐蔽吧,搞了一天了。。。因为这样才会出现 Error setting expression 'age' with value ['6789', ]  -->


            <!-- 返回json类型数据 -->
            <result type="json">
                <param name="root">result<!-- result是action中设置的变量名,也是页面需要返回的数据,该变量必须有setter和getter方法 --></param>
            </result>
        </action>         
    </package>


后台action接收jquery请求传来的年龄数据:

public class JsonAjaxAction extends ActionSupport implements ServletRequestAware{
    private static final long serialVersionUID = 1L;

   private String result;
   public String getResult() {
       return result;
   }
   public void setResult(String result) {
       this.result = result;

   }

public void setServletRequest(HttpServletRequest arg0) {
        this.request = arg0;
    }

public String excuteAjax(){    //注意方法名

int age = Integer.parseInt(request.getParameter("age"));    

       try {
           JSONObject jo = new JSONObject();
           jo.element("age", age);//问题来了,无法通过setter把请求中age的值获取到
           result=jo.toString();
              } catch (Exception e) {
           e.printStackTrace();
       }
       return SUCCESS;
   }

}


0 0
原创粉丝点击