type=json

简介:

在Struts2中,type="json“这样是用来做AJAX请求的  
所以根本就没有跳转页面。
json是一种数据格式,具体可以网上去学习一下。
在Struts2中,如果这样写,会将你Action中的变量转成JSON 返回到页面
用来做AJAX是非常方便的。

 

只要继承extends="json-default",result type设置成json之后,容器会把action的属性自动封装到一个json对象中(json拦截器来做)

 

1, ignoreHierarchy 参数:默示是否忽视等级,也就是持续关系,比如:TestAction 持续于 BaseAction,那么 TestAction 中返回的 json 字符串默认是不会包含父类 BaseAction 的属性值,ignoreHierarchy 值默认为 true,设置为 false 后会将父类和子类的属性一路返回。

<result type=”json”>
    <paramname=”ignoreHierarchy”>false</param>
</result>

2, excludeNullProperties 参数:默示是否去掉空值,默认值是 false,若是设置为 true 会主动将为空的值过滤,只输出不为空的值。

<result ype=”json”>
     <paramname=”excludeNullProperties”>true</param>
</result>

3, root 参数:从返回成果中按照 ognl 表达式取出你须要输出的成果。 只输出 person 对象的 name 属性值,设备如下:

<result type=”json”>
     <param name=”root”>person.name</param>
</result>

4, includeProperties 参数:输出成果中须要包含的属性值,这里正则表达式和属性名匹配,可以用 “,” 分别填充多个正则表达式。

<result type=”json”>
   <param name=”includeProperties”>person.*, person.name</param>
</result>

5, excludeProperties 参数:输出成果须要剔除的属性值,也支撑正则表达式匹配属性名,可以用 “,” 分别填充多个正则表达式,类同 includeProperties 参数。



本文转自农夫山泉别墅博客园博客,原文链接:http://www.cnblogs.com/yaowen/archive/2013/03/17/2964391.html,如需转载请自行联系原作者

相关文章
|
JSON 前端开发 JavaScript
JSON parse error: Cannot deserialize value of type `java.lang.Integer` from Boolean value
这篇文章讨论了前端Vue应用向后端Spring Boot服务传输数据时发生的类型不匹配问题,即后端期望接收的字段类型为`int`,而前端实际传输的类型为`Boolean`,导致无法反序列化的问题,并提供了问题的诊断和解决方案。
JSON parse error: Cannot deserialize value of type `java.lang.Integer` from Boolean value
|
JSON 数据格式 Python
【python】解决json.dump(字典)时报错Object of type ‘float32‘ is not JSON serializable
在使用json.dump时遇到的“Object of type ‘float32’ is not JSON serializable”错误的方法,通过自定义一个JSON编码器类来处理NumPy类型的数据。
569 1
|
JSON 前端开发 数据格式
【Python】已解决:TypeError: Object of type JpegImageFile is not JSON serializable
【Python】已解决:TypeError: Object of type JpegImageFile is not JSON serializable
267 0
|
JSON 数据格式
Unsupported Media Type,传入的字符串数据:这里应该是Json
Unsupported Media Type,传入的字符串数据:这里应该是Json
|
JSON 数据格式
Content type ‘text/plain;charset=UTF-8‘ not supported,这里要把测试文件转为json格式
Content type ‘text/plain;charset=UTF-8‘ not supported,这里要把测试文件转为json格式
Warning: To load an ES module, set “type“: “module“ in the package.json or use the .mjs extension.
Warning: To load an ES module, set “type“: “module“ in the package.json or use the .mjs extension.
|
JSON 数据格式
gson自定义Type解析json数组字符串
gson自定义Type解析json数组字符串
184 0
|
JSON 数据格式
TypeError: Object of type ‘float32‘ is not JSON serializable
TypeError: Object of type ‘float32‘ is not JSON serializable
338 0
|
JSON Java 数据格式
HttpMediaTypeNotSupportedException: Content type ‘application.yml/json;charset=UTF-8‘ not supported
HttpMediaTypeNotSupportedException: Content type ‘application.yml/json;charset=UTF-8‘ not supported
442 0
|
JSON 数据格式 Python
TypeError: Object of type 'datetime' is not JSON serializable
TypeError: Object of type 'datetime' is not JSON serializable
225 0