Unexpected Exception caught setting 'age'-Error setting expression 'age' with value ['3']
来源:互联网 发布:mmd怎么制作动作数据 编辑:程序博客网 时间:2024/06/08 15:01
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;
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;
}
}
- Unexpected Exception caught setting 'age'-Error setting expression 'age' with value ['3']
- Unexpected Exception caught setting 'x' on class xx:Error setting expression 'xx' with value ['x',]
- Unexpected Exception caught setting
- Error setting expression '.css' with value
- Error setting expression '0' with value '/'
- struts2 Error setting expression XXXX with value
- Error setting expression 'token' with value...
- Error setting expression 'orderid' with value ['2', ]
- 报错:Unexpected Exception caught setting 'undefined'
- Unexpected Exception caught setting 'xx' on 'xxx'
- Unexpected Exception caught setting 异常解决记录
- Unexpected Exception caught setting 'upfile' on 'class yuhao.action.FileAction: Error setting expres
- Unexpected Exception caught setting 'username' on 'class cn.lim.action.UserAction: Error setting exp
- Error setting expression 'XXX' with value [Ljava.lang.String;@...
- Error setting expression 'image' with value '[Ljava.lang.String;@e41d4a'
- 图片上传是出现Error setting expression 'upload' with value '
- SSH2开发错误RROR - ParametersInterceptor - [setParameters]: Unexpected Exception caught setting
- Unexpected Exception caught setting 'house.floorage' on 'class action.HouseAction
- LeetCode:Maximum Depth of Binary Tree
- ng-if和ng-show、ng-hide区别
- FFPLAY的原理(二)
- lighttpd安装与配置
- PHP是一门高效的网络编程语言
- Unexpected Exception caught setting 'age'-Error setting expression 'age' with value ['3']
- 第16周项目2-用指针玩字符串(4)字符串单词数
- 学而时习之不亦乐乎
- Android Hook框架Xposed原理与源代码分析
- 视图控制器的生命周期
- FFPLAY的原理(三)
- MySQL数据库中对于网卡绑定对授权和访问的影响测试一例
- Android内存问题的几种解决方案(二)
- Install Redmine on Centos 6.5 - 64 bit