微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

浅谈ajax在jquery中的请求和servlet中的响应

在jsp中,首先,你需要导入jquery的架包:

获取可返回站点的根路径:

rush:xhtml;"> <% String path = request.getContextPath(); %>

在jquery中写ajax请求:

rush:xhtml;">

jsp部分:

rush:xhtml;">
序号

在servlet中用到了阿里巴巴的快速转换json的包com.alibaba.fastjson.JSON:

rush:xhtml;"> private void queryEvaluateByuserId(HttpServletRequest request,HttpServletResponse response) throws sqlException,IOException,servletexception{ HttpSession session=request.getSession(); request.setCharacterEncoding("UTF-8"); response.setContentType("text/html"); response.setCharacterEncoding("UTF-8"); Cookie[] cookies = request.getCookies(); int ownerId = 0; for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; if (cookie.getName().equals("ownerId")) { ownerId = Integer.parseInt(cookie.getValue()); } } List orderList = new ArrayList<>(); List queryEvaluateList = new ArrayList<>(); orderList = orderServiceImpl.queryOrderList(ownerId,null,null); List> workers = new ArrayList>(); for(int i = 0;i < orderList.size();i++){ Map order = new HashMap(); order.put("description",orderList.get(i).getDescription()); order.put("name",orderList.get(i).getownerName()); System.out.println(orderList.get(i).getDescription()); order.put("type",orderList.get(i).getTypeName()); queryEvaluateList = orderServiceImpl.queryEvaluateListByUserId(orderList.get(i).getId()); order.put("comment",queryEvaluateList.get(0).getComment()); List allocation = orderServiceImpl.queryAllocationByOrderId(orderList.get(i).getId()); order.put("price",String.valueOf(allocation.get(0).getPrice())); System.out.println(order); workers.add(order); } //将map键值对转换成json,传给jsp response.getoutputStream().write(JSON.toJSONBytes(workers)); }

以上这篇浅谈ajax在jquery中的请求和servlet中的响应就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程之家。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


业主名 金额