前后台数据交换,printwriter、jsonobject、jsonarray、ajax请求,数据交换
后台代码:
public void findByIDEquipment() {
getResponse().setCharacterEncoding("UTF-8");
getResponse().setContentType("text/html;charset=UTF-8");
PrintWriter out;
JSONObject obj = new JSONObject();
JSONArray jarr = new JSONArray();
ArrayList<Equipment> eq_array_list = new ArrayList<Equipment>();
SimpleDateFormat sdf = new SimpleDateFormat();
try {
out = getResponse().getWriter();
System.out.println(eq_id);
long id = Long.valueOf(getRequest().getParameter("eq_id"));
System.out.println("id is" + id);
Equipment eq = eq_service.findEquipmentById(id);
Equipment eq1 = eq;
eq_array_list.add(eq);
if (eq != null) {
/*
* getSession().setAttribute("eq_name", eq.getName());
* getSession().setAttribute("eq_comment", eq.getComment());
* getSession().setAttribute("eq_pn", eq.getPn());
* getSession().setAttribute("eq_sn", eq.getSn());
* getSession().setAttribute("eq_inDate", eq.getInDate());
* getSession().setAttribute("eq_alarmDay",
* eq.getAlarmTimeDay());
* getSession().setAttribute("eq_overTime", eq.getOverTime());
* getSession().setAttribute("eq_username",
* eq.getEq_user().getUsername());
*/
obj.put("eq1", eq1);
obj.put("indate", sdf.format(eq1.getInDate()));
obj.put("overdate", sdf.format(eq1.getOverTime()));
jarr.add(obj);
out.print(jarr);
out.flush();
} else {
out.println(false);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
前台代码:
/* 详情动作 */
$('.action_div')
.click(
function() {
var click_num = $('.action_div').index(this)
console.log(click_num)
var eq_id = $('.action_div').eq(click_num).attr('org')
console.log("select item id is" + eq_id) $.ajax({
type : "POST",
url : "findByIDEquipmentAction?fresh="
+ Math.random(),
data : {
"eq_id" : eq_id
},
cache : false,
async : true,
dataType : "json",
success : function(res) {
console.log(res)
console.log(res[0].eq1.name) if (res) { $('.getname').text(res[0].eq1.name)
$('.getcomment').text(res[0].eq1.comment)
$('.getpn').text(res[0].eq1.pn)
$('.getsn').text(res[0].eq1.sn)
$('.getindate').text(
res[0].indate.toString().substring(
0, 8))
$('.getalarmday').text(
res[0].eq1.alarmTimeDay)
$('.getoverdate').text(
res[0].overdate.toString()
.substring(0, 8))
$('.getusername').text(
res[0].eq1.eq_user.username) } else {
alert("请求异常1");
} },
error : function(json) {
alert("请求异常2");
}
}) $('#mask2')
.css(
{
"opacity" : "1",
"z-index" : "100",
'-webkit-transition' : 'opacity 2s ease-in,z-index 1s ease-in',
'-moz-transition' : 'opacity 2s ease-in,z-index 1s ease-in',
'-ms-transition' : 'opacity 2s ease-in,z-index 1s ease-in',
'-o-transition' : 'opacity 2s ease-in,z-index 1s ease-in',
'transition' : 'opacity 2s ease-in,z-index 1s ease-in' }) })
public void findByIDEquipment() {getResponse().setCharacterEncoding("UTF-8");getResponse().setContentType("text/html;charset=UTF-8");PrintWriter out;JSONObject obj = new JSONObject();JSONArray jarr = new JSONArray();ArrayList<Equipment> eq_array_list = new ArrayList<Equipment>();SimpleDateFormat sdf = new SimpleDateFormat();try {out = getResponse().getWriter();
System.out.println(eq_id);
long id = Long.valueOf(getRequest().getParameter("eq_id"));System.out.println("id is" + id);Equipment eq = eq_service.findEquipmentById(id);Equipment eq1 = eq;eq_array_list.add(eq);if (eq != null) {/* * getSession().setAttribute("eq_name", eq.getName()); * getSession().setAttribute("eq_comment", eq.getComment()); * getSession().setAttribute("eq_pn", eq.getPn()); * getSession().setAttribute("eq_sn", eq.getSn()); * getSession().setAttribute("eq_inDate", eq.getInDate()); * getSession().setAttribute("eq_alarmDay", * eq.getAlarmTimeDay()); * getSession().setAttribute("eq_overTime", eq.getOverTime()); * getSession().setAttribute("eq_username", * eq.getEq_user().getUsername()); */obj.put("eq1", eq1);obj.put("indate", sdf.format(eq1.getInDate()));obj.put("overdate", sdf.format(eq1.getOverTime()));jarr.add(obj);
out.print(jarr);out.flush();
} else {out.println(false);}
} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}
}
前后台数据交换,printwriter、jsonobject、jsonarray、ajax请求,数据交换的更多相关文章
- session失效,使用ajax请求数据被拦截,此时正常的处理逻辑是跳到登录界面,而不是界面没有变化(java推断是否是ajax请求)
在登录过滤器中.推断请求是ajax请求还是超链接或者地址栏变化的请求 if (httpServletReq.getHeader("x-requested-with") != nul ...
- dotnet webservice处理数据量过大,ajax请求返回500错误解决方案
ajax请求webservice返回json数据,数据规模过大时ajax请求会得到500的响应,webservice+ajax处理大规模的数据需要在web.config中进行如下配置: <sys ...
- 关于ajax请求数据,并将数据赋值给全局变量的一些解决方法
在使用ajax请求数据是,开始的时候是打算将ajax的数据取出,并赋予给全局变量,但是在实际编码过程中发现并不能将数据赋予给最开始定义的全局变量,出现这个问题的原因是由于ajax异步加载的原因,所以只 ...
- vue使用element Transfer 穿梭框实现ajax请求数据和自定义查询
vue使用element Transfer 穿梭框实现ajax请求数据和自定义查询 基于element Transfer http://element-cn.eleme.io/#/zh-CN/comp ...
- Ajax请求数据的两种方式
ajax 请求数据的两种方法,有需要的朋友可以参考下. 实现ajax 异步访问网络的方法有两个.第一个是原始的方法,第二个是利用jquery包的 原始的方法不用引入jquery包,只需在html中编写 ...
- Ajax请求数据与删除数据后刷新页面
1.ajax异步请求数据后填入模态框 请求数据的按钮(HTML) <a class="queryA" href="javascript:void(0)" ...
- ajax 请求数据的两种方法
实现ajax 异步访问网络的方法有两个.第一个是原始的方法,第二个是利用jquery包的 原始的方法不用引入jquery包,只需在html中编写script 片段 这里我演示的是一个传递参数查询的例子 ...
- h5-localStorage实现缓存ajax请求数据
使用背景:要实现每次鼠标hover“能力雷达”,则显示能力雷达图(通过ajax请求数据实现雷达图数据显示),所以每次hover都去请求ajax会影响性能,因此这里要用到本地缓存. 实现: 此处是通过传 ...
- 使用Python的Flask框架,结合Highchart,动态渲染图表(Ajax 请求数据接口)
参考链接:https://www.highcharts.com.cn/docs/ajax 参考链接中的示例代码是使用php写的,这里改用python写. 需要注意的地方: 1.接口返回的数据格式,这个 ...
- 关于ajax请求数据后,数据本身的js失效的一些想法
今天遇到一个头疼的问题.我做一个左右翻页效果(客户要求能够无限翻页),所以只能动态请求数据,进行局部刷新操作. 这时候问题就出来了,当我请求翻页的时候,数据通过js填充到div里面,但这些数据,自身带 ...
随机推荐
- vue中使用ajax
var vue = new Vue({ el:"#vueid", data:{ selectById : "", }, methods:{ yourMethod ...
- ubuntu 14.04 重装机 安装笔记 无线网卡+cuda+nvidia
1. 安装QA6714 无线网卡重要参考网页 #22 回答 https://bugs.launchpad.net/ubuntu/+source/linux-firmware/+bug/1520343? ...
- tomcat下服务启动失败原因
Tomcat启动成功,输入网址后可以显示小黄猫界面,但是在Tomcat下的服务却启动不成功,显示404(以Jenkins为例,运用多种方式查看原因) 注:1.单启动Tomcat服务是可以启动成功的. ...
- 利用python执行shell脚本 并动态传参 及subprocess基本使用
最近工作需求中 有遇到这个情况 在web端获取配置文件内容 及 往shell 脚本中动态传入参数 执行shell脚本这个有多种方法 最后还是选择了subprocess这个python标准库 su ...
- matlab函数每天进步一点点
1. 读mp4视频 : xyloObj = VideoReader('su35.mp4'); 链接 2. 查看有几个相同的函数和当前使用的函数是哪个路径下的: which -all xxx; w ...
- 七、Django模型基础第二节——常用查询
1 常用的模型字段类型 官方文档链接: https://docs.djangoproject.com/en/2.1/ref/models/fields/#field-types 常用的字段类型 模型字 ...
- FlappyBirdWeb素材资源
https://pan.baidu.com/s/1UeNmhnmK4RInmfiEduPrAQ 先上网盘地址 https://github.com/JIANGYUJING1995/FlappyBird ...
- 微信小程序登录(包括获取不到unionid的情况)
我们一般都是先获取到微信的 unionid,然后再通过 unionid 去登录自己的网站,就可以关联到用户在自己网站上的 user_id,但是在小程序登录中,有时候可以获取到 unionid,有时候获 ...
- UVA10562(看图写树,dfs)
这个题过的好艰难,不过真的学到好多. 关于fgets的用法真的是精髓.!isspace(c)和c!=' '是有区别的. 其它的看代码吧 #include <iostream> #inclu ...
- sku
以淘宝为例,sku是具体到某一个商家具体规格商品,比如某商家红色64g的iPhone6,sku对应有对应的价格和库存.而SPU就是我们在输入框里输入的iPhone6,它是多个商家的集合.淘宝的“宝贝” ...