- 浏览: 756725 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (981)
- javascript (102)
- java (212)
- JQuery (81)
- 幽默笑话 (2)
- 只言片语 (6)
- 开发小记 (283)
- Hibernate (17)
- DWR (4)
- SQL (10)
- spring-ibatis (8)
- linux (24)
- Struts1 (8)
- Struts2 (16)
- spring (42)
- Mybatis (16)
- css (18)
- servlet (8)
- jdbc (4)
- jsp (1)
- spring-jdbc (2)
- FreeMarker (2)
- MySQL (24)
- JQuery-Grid (7)
- jstl (5)
- 正则表达式 (1)
- 面试集锦 (86)
- unix (18)
- 开发工具 (23)
- ajax (5)
- webservice (4)
- log4j (3)
- oracle (15)
- extjs (14)
- 其他 (9)
- 优秀技术参考地址 (1)
- 性能 (3)
- 数据库 (25)
- 算法 (15)
- 设计模式 (10)
- Python (3)
- AIX (5)
- weblogic (1)
- shell (14)
- quartz (5)
- 图形文件FusionCharts (1)
- Websphere (4)
- 转载 (5)
- hadoop (1)
- highchart (24)
- perl (22)
- DB2 (7)
- JBoss (1)
- JQuery Easy UI (9)
- SpringMVC (5)
- ant (5)
- echart (9)
- log4J配置 (3)
- 多线程 (10)
- 系统架构 (7)
- nginx (3)
- loadrunner1 (1)
- 分布式 (1)
- Dubbo (1)
- Redis (2)
- JMS (4)
- 自动化测试 (3)
- Spring循环依赖的三种方式 (1)
- spring-boot (2)
- 高级测试 (9)
- github (2)
- sonar (1)
- docker (6)
- web前端性能优化 (1)
- spring-aop (6)
- rabbit (1)
- ELK (1)
- maven (1)
- minio (1)
最新评论
-
zengshaotao:
jstl1point0 写道很好啊,如果有带Session会话 ...
Nginx+Tomcat搭建高性能负载均衡集群 -
jstl1point0:
很好啊,如果有带Session会话的怎么搞呢
Nginx+Tomcat搭建高性能负载均衡集群
struts2.1.8以后,加入了json的plugin插件包,使用时仅需把插件包(struts2-json-plugin-2.2.1.1.jar)放入到项目中的WEB-INF/lib下面就可以。这里重点解释返回结果result中的root参数的含义,相对于其他参数,例如includeProperties, excludeProperties,excludeNullProperties等,比较难以理解。
(1)struts.xml 配置:
<struts>
<constant name="struts.i18n.encoding" value="UTF-8" />
<package name="default" namespace="/" extends="json-default">
<action name="jsontest" class="com.test.action.JsonJqueryStruts2Action">
<result name="regInfo" type="json">
<param name="root">userInfo</param>
<!-- <param name="includeProperties">userInfo.userId,userInfo.userName</param> -->
<param name="includeProperties">userId,userName</param>
<param name="excludeNullProperties">true</param>
</result>
</package>
</struts>
(2)Action类:类中有一个String类型的属性message,以及一个bean叫UserInfo
public class JsonJqueryStruts2Action extends ActionSupport {
private String message; //使用json返回单个值
private UserInfo userInfo; //使用json返回对象
... ...
(3)表单:form中必须与Action类中的属性名字大小写完全对应,不然会找不到该字段
<form>
用户ID:<input name="userInfo.userId" type="text"/><br/>
用户名:<input name="userInfo.userName" type="text"/><br/>
... ...
(4)json.js文件的ajax方法:
//向服务器发送表达数据
$("#regRe").click(function(){
//把表单的数据进行序列化
var params = $("form").serialize();
(1)struts.xml 配置:
<struts>
<constant name="struts.i18n.encoding" value="UTF-8" />
<package name="default" namespace="/" extends="json-default">
<action name="jsontest" class="com.test.action.JsonJqueryStruts2Action">
<result name="regInfo" type="json">
<param name="root">userInfo</param>
<!-- <param name="includeProperties">userInfo.userId,userInfo.userName</param> -->
<param name="includeProperties">userId,userName</param>
<param name="excludeNullProperties">true</param>
</result>
</package>
</struts>
(2)Action类:类中有一个String类型的属性message,以及一个bean叫UserInfo
public class JsonJqueryStruts2Action extends ActionSupport {
private String message; //使用json返回单个值
private UserInfo userInfo; //使用json返回对象
... ...
(3)表单:form中必须与Action类中的属性名字大小写完全对应,不然会找不到该字段
<form>
用户ID:<input name="userInfo.userId" type="text"/><br/>
用户名:<input name="userInfo.userName" type="text"/><br/>
... ...
(4)json.js文件的ajax方法:
//向服务器发送表达数据
$("#regRe").click(function(){
//把表单的数据进行序列化
var params = $("form").serialize();
对于中文,注意乱码的处理,前面已经有文章说过了。
//使用jQuery中的$.ajax({});Ajax方法
$.ajax({
url:"jsontest!regUserInfo.action",
type:"POST",
data:params,
dataType:"json",
success:function(data){
//清空显示层中的数据
$("#message").html("");
//为显示层添加获取到的数据
//获取对象的数据用data.userInfo.属性
//$("#message").append("<div><font color='red'>用户ID:"+data.userInfo.userId+"</font></div>")
//.append("<div><font color='red'>用户名:"+data.userInfo.userName+"</font></div>")
$("#message").append("<div><font color='greed'>111:"+data.userId+"</font></div>");
$("#message").append("<div><font color='greed'>222:"+data.userName+"</font></div>");
if( typeof(data.message)!='undefined' ){
$("#message").append("<div><font color='greed'>结果:"+data.message+"</font></div>");
}else{
$("#message").append("<div><font color='greed'>结果是message没定义!"+data.message+"</font></div>");
}
... ...
以上是jquery+json+struts2的主要核心配置和代码,请注意struts2配置中指定了result的name="root",所谓root的含义,是指返回的json数据的根为root中指定的bean类,例如此处为userInfo,如果没有指定root属性,则默认使用Action作为返回的json数据的根,区别如下:
result中使用了root参数后返回的json数据:
{"userInfo":[
{"userId":"Patrick", "userName":"123456"}
]}
result中没设置root参数返回Action中的json数据:
{"data":[
{"userInfo":[ {"userId":"Patrick", "userName":"123456"} ] },
{"message":"testMesssageData"}
]}
所以我们要注意,如果设置了root属性之后,<param includeProperties></param>中就应该直接使用userId,userName而非userInfo.userId,userIndo.userName了。
此外,json.js代码中还展示了遇到类似message等属性返回后是undefined的情况可以使用typeof()!='undefined'进行判断
//使用jQuery中的$.ajax({});Ajax方法
$.ajax({
url:"jsontest!regUserInfo.action",
type:"POST",
data:params,
dataType:"json",
success:function(data){
//清空显示层中的数据
$("#message").html("");
//为显示层添加获取到的数据
//获取对象的数据用data.userInfo.属性
//$("#message").append("<div><font color='red'>用户ID:"+data.userInfo.userId+"</font></div>")
//.append("<div><font color='red'>用户名:"+data.userInfo.userName+"</font></div>")
$("#message").append("<div><font color='greed'>111:"+data.userId+"</font></div>");
$("#message").append("<div><font color='greed'>222:"+data.userName+"</font></div>");
if( typeof(data.message)!='undefined' ){
$("#message").append("<div><font color='greed'>结果:"+data.message+"</font></div>");
}else{
$("#message").append("<div><font color='greed'>结果是message没定义!"+data.message+"</font></div>");
}
... ...
以上是jquery+json+struts2的主要核心配置和代码,请注意struts2配置中指定了result的name="root",所谓root的含义,是指返回的json数据的根为root中指定的bean类,例如此处为userInfo,如果没有指定root属性,则默认使用Action作为返回的json数据的根,区别如下:
result中使用了root参数后返回的json数据:
{"userInfo":[
{"userId":"Patrick", "userName":"123456"}
]}
result中没设置root参数返回Action中的json数据:
{"data":[
{"userInfo":[ {"userId":"Patrick", "userName":"123456"} ] },
{"message":"testMesssageData"}
]}
所以我们要注意,如果设置了root属性之后,<param includeProperties></param>中就应该直接使用userId,userName而非userInfo.userId,userIndo.userName了。
此外,json.js代码中还展示了遇到类似message等属性返回后是undefined的情况可以使用typeof()!='undefined'进行判断
发表评论
-
input 隐藏 方法传入字符串参数
2020-04-12 14:02 583JQuery 使用 $("#input[id='' ... -
JQuery 之empty and remove
2017-12-25 18:59 404$("table tr[id^=trAddColum ... -
easyui dialog隐藏与显示
2017-12-13 18:30 1494有时候需要对查询的结果进行过滤,当然如果是前端过滤,就不要再 ... -
cookie操作 JQuery
2017-03-23 22:18 484首先包含jQuery的库文件,在后面包含 jquery.coo ... -
表单参数一并提交
2017-03-23 13:09 532对于一般的table数据,并且还带有查询条件,我们都会使用j ... -
JQuery解析XML
2017-03-19 17:26 452用JavaScript解析XML数据是常见的编程任务,Ja ... -
表格动态展示与下钻
2016-09-13 08:37 1242<%@ page language="jav ... -
JQuery tree的使用
2016-07-12 09:32 1056$(function(){ $('#cardTree') ... -
兄弟frame之间控制页面
2016-05-17 18:05 834<FRAMESET cols=" ... -
easy ui 树的常用功能
2016-05-17 14:40 618遍历tree nodes function Trav ... -
attr(),css()
2016-05-04 17:54 389JQuery的attr()方法,设置属性,不同于css(), ... -
$.browser.msie为空
2016-03-03 17:34 447'$.browser.msie' 为空或不是对象,这个是j ... -
jOrgChart 后端取数--递归构建map
2016-03-03 11:41 736<!DOCTYPE html> <htm ... -
jOrgChart 后端取数--手工构建map
2016-03-03 11:39 617<!DOCTYPE html> <htm ... -
jOrgChart横向的组织机构树--手工构造json数据
2016-03-02 17:41 1202<!DOCTYPE html> <htm ... -
jOrgChart的调试模式
2016-03-02 14:41 1109jOrgChart是一个不错的横向组织树插件,在视觉体验上也 ... -
jOrgChart横向的组织机构数插件
2016-03-02 12:03 883<!DOCTYPE html> <htm ... -
easy ui data grid
2016-02-22 16:40 920JQuery Easy Ui dataGrid 数据表格 ... -
JQuery easy ui 图标扩展
2015-12-23 15:44 940JQuery easy ui 1.2.6有很多的图标, ... -
获取页面高度
2015-12-15 10:26 429$(document).height() //是获取整个页 ...
相关推荐
<package name="json" extends="json-default" namespace="/" > <result type="json"> <param name="root">result </result> </struts>
有两种做法:os.walk()、pathlib...analysis_root_dir = D:\\analysis_data\json_file store_result=D:\\analysis_data\\analysis_result\\dependency.csv def parse_dir(root_dir): path = Path(root_dir) all_json_
const Root = new ApiService ( fetch , { url : "/api" } ) . use ( jsonApiPlugin ) // <- Add this line 用法 想象一下,我们的API路由具有以下result.body : { " data " : [ { " id
self.failed = root.getAttribute('failed') self.skipped = root.getAttribute('skipped') #构建的次数统计在json⽂件中 file = open(REPORT_URL_FILE,'r') self.reportUrl=json.load(file)['reportUrl'] #发送报告...
检查你代码的 JSONEObject.fromObject(result) 代码位置,参数result不符合Json的定义格式,所以无法转换成Json格式,导致报出上述错误。 解决办法: 好好检查下你的result参数,按照Json规范定义。 如果一定要输出...
e)XML_BODY:xml数据请求方式key名称,默认为root f)MONITOR_FILE_PATH:统计数据保存地址 默认为/report/report.cc g)END_INVOKE:请求通道链终端类。 系统默认 <!--如果不是采用report返回体,则必须配置以下几项,...
$.getJSON($SCRIPT_ROOT + '/_add_numbers',data, function(data) { $('#result').text(data.result); $('input[name=a]').focus().select(); }); 后端pthon代码如下 # ajax,Get方式与js交互(非
<param name="root">result </result> 在页面抓取中转信息,回显 $.post("${pageContext.request.cotnextPath}/processinstance_showInfo.action", {"pid": pid}, function(data){ $.messager.alert(...
支持bigdecimal,json解码,async_std,tokio use rbatis_core :: db :: {DBPool}; fn main () -> Result <(), rbatis_core::Error>{ async_std :: task :: block_on ( async move { //Automatic judgment of...
Mininet + Ryu路由算法比较器 一堆脚本和文件,描述了拓扑创建,拓扑,测试数据,实时图形... 以root身份运行make 。 可以安全删除的文件 rm -rf boxplots rm -rf resultcache rm -rf *.json rm -rf *.pdf rm -rf
/** * ECSHOP 首页文件 * ====================... die($json->encode($result)); } /*------------------------------------------------------ */ //-- 判断是否存在缓存,如果存在则调用缓存,反之读取相应内容
select ( [ { $root : '.result' , title : '.title' , link : 'a[href]' } ] ) . write ( 'out.json' ) ;应用程序接口xray#request(url, fn) 使用 Request 发出请求车身处理器此驱动程序接受可选的主体处理器。 第...
root.done(err, JSON.parse(body).code); }); }, [appId], [redirectUri]) .step('getToken', function(code) { var root = this; request.post('[token_uri]', function(err, res, body) {...
$array_data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true); return $array_data; } /** * 作用:以post方式提交xml到对应的接口url */ public ...
$.getJSON(url,[data],[fn]) $.getScript(url,[callback]) $.post(url,[data],[fn],[type]) ajax 事件 ajaxComplete(callback) ajaxError(callback) ajaxSend(callback) ajaxStart(callback) ajaxStop...
@DB(url="jdbc:mysql://127.0.0.1:3306/test" ,username="root", password="root") 一些基本的数据库操作: //insert new User().setName("zzg.zhou").setStatus(1).save(); //parse data from type: Map, ...
The FileResult action result now supports non-US-ASCII characters in file names. Methods and properties of the TempDataDictionary class have been improved to better handle the case when items are ...