这篇文章给大家分享的是有关json格式中Ajax提交的示例分析的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
创新互联专注于玛沁网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供玛沁营销型网站建设,玛沁网站制作、玛沁网页设计、玛沁网站官网定制、小程序定制开发服务,打造玛沁网络公司原创品牌,更为您提供玛沁网站排名全网营销落地服务。
需要加入:com.springsource.org.apache.commons.logging-1.1.1.jar、org.json.jar和jquery-1.10.0.min.js包
package com.utcsoft.pcapps.selfservice.controller; import java.io.IOException; import java.io.PrintWriter; import java.net.UnknownHostException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.json.JSONException; import org.json.JSONObject; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import com.utcsoft.common.attributes.YesNoEnum; import com.utcsoft.common.util.DateOperate; import com.utcsoft.pcapps.selfservice.attributes.KeyRequestAttr; import com.utcsoft.pcapps.selfservice.dao.FlowDao; import com.utcsoft.pcapps.selfservice.dao.KeyRequestDao; import com.utcsoft.pcapps.selfservice.entity.Flow; import com.utcsoft.pcapps.selfservice.entity.KeyRequest; import com.utcsoft.pcapps.selfservice.entity.UtcUsers; @Controller @RequestMapping(value = "/asynchronous") public class AsynchronousController { private final static Log logger = LogFactory.getLog(AsynchronousController.class); /** * 扫描二维码 将订单改为UTC审核 * @param request * @param response * @throws IOException * @throws JSONException */ @RequestMapping(value="/receive") public void receive(HttpServletRequest request,HttpServletResponse response) throws IOException, JSONException{ String rets = ""; boolean b = false; try{ String qrcode = request.getParameter("qrCode")==null?"":request.getParameter("qrCode").toString().trim(); logger.info(qrcode); if(!"".equals(qrcode)){ JSONObject obj = new JSONObject(qrcode); String orderid = obj.getString("orderid").trim(); if(!"".equals(orderid)){ KeyRequestDao keyDao = new KeyRequestDao(); KeyRequest k = new KeyRequest();//综合信息 k = keyDao.findOneByOrderId(orderid); if(k!=null){ //修改订单状态为审核 int n = keyDao.updateState(orderid, String.valueOf(KeyRequestAttr.KqStateEnum.verify.getStep())); Flow flow = new Flow(); FlowDao flowDao = new FlowDao(); UtcUsers users = (UtcUsers)request.getSession().getAttribute("utcUsers"); //将记录插入Flwo表中 flow.setKq_id(orderid); flow.setKq_state(String.valueOf(KeyRequestAttr.KqStateEnum.cus_send.getStep())); flow.setKq_state_to(String.valueOf(KeyRequestAttr.KqStateEnum.verify.getStep())); flow.setIs_Pass(YesNoEnum.Y.getCode()); flow.setUser_id(users.getUser_id()); flow.setUser_id_from(users.getUser_id()); flow.setOpTimer(DateOperate.getDateTime()); int flowNum = flowDao.save(flow); logger.info("扫描二维码提交结果:n="+n+";flowNum="+flowNum); if(n>0){ b = true; rets = "UTC接收订单成功"; logger.info("UTC接收订单成功"); } else{ rets = "UTC接收订单失败"; logger.info("UTC接收订单失败"); } } else{ rets = "订单查询失败"; logger.info("订单查询失败"); } } else{ rets = "二维码中订单号为空"; logger.error("二维码中订单号为空"); } } else{ rets = "二维码内容为空"; logger.error("二维码内容为空"); } } catch(Exception e){ e.printStackTrace(); rets = e.getMessage(); logger.error(e.getMessage()); } JSONObject ret = new JSONObject(); ret.put("flag", b); ret.put("info", rets); PrintWriter write = response.getWriter(); write.write(ret.toString()); write.flush(); } }感谢各位的阅读!关于“json格式中Ajax提交的示例分析”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!