ajax请求printwrite,前后台数据交换,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 eq_array_list = new ArrayList();

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 eq_array_list = new ArrayList();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();}

}

标签:getSession,printwriter,jsonarray,数据交换,setAttribute,eq1,eq,id,out

来源: https://www.cnblogs.com/dingjiuping/p/printwriter_jsonobject_jsonarray_ajax_data_switch.ht

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值