zoukankan      html  css  js  c++  java
  • form表单数据封装成json格式并提交给服务器

    1、jsp代码,form表单:
      1 <form action="#" id="costForm">
      2 <input type="hidden" id="userId" name="userId"/>
      3 <div id="COST">
      4     <img src='<%=path %>/cvc/center/images/close.png' class="close" style="34px;position:absolute;right:0px;top:0px;"></img>
      5     <h2 style="font-weight: bolder;font-size: 14px;">更改该注册订单的收费状态</h2>
      6     <ul>
      7     <li>
      8         <label for="report">
      9              是否已报到:
     10         </label>
     11         <input type="radio" id="baodao1" name="baodao" value="1"/> 12         <input type="radio" id="baodao0" name="baodao" value="0"/> 13     </li>
     14 
     15     <li>
     16         <label for="name">
     17               姓  名:
     18         </label>
     19         <span id="costName"></span>
     20     </li>
     21 
     22     <li>
     23         <label for="type">
     24               注册类型:
     25         </label>
     26         <span id="costType"></span>
     27     </li>
     28     <li>
     29         <label for="sure_fee">
     30              在线支付手续费:
     31         </label>
     32        <span id="costType">0</span>
     33     </li>
     34     <li>
     35         <label for="sure_fee">
     36               应收费金额:
     37         </label>
     38         <span id="price"></span>
     39     </li>
     40 
     41     <li>
     42         <label for="already_fee">
     43               已收费金额:
     44         </label>
     45         <input type="text" id="pay_" name="pay"/>
     46     </li>
     47 
     48     <li>
     49         <label for="owe">
     50               欠  款:
     51         </label>
     52         <span id="qianPay"></span>
     53     </li>
     54 
     55     <li>
     56         <label for="fee_type">
     57               付款方式:
     58         </label>
     59         <input type="radio" id="payType1" name="payType" value="3"/>银行
     60         <input type="radio" id="payType2" name="payType" value="4"/>邮局
     61         <input type="radio" id="payType3" name="payType" value="5"/>现金
     62         <input type="radio" id="payType4" name="payType" value="2"/>在线支付
     63     </li>
     64 
     65     <li>
     66         <label for="fee_evidence">
     67                    是否收到汇款凭证:
     68         </label>
     69         <input type="radio" id="isReceiveProof1" name="isReceiveProof" value="1"/> 70         <input type="radio" id="isReceiveProof0" name="isReceiveProof" value="0"/> 71     </li>
     72 
     73     <li>
     74         <label for="fa_piao">
     75               发票抬头:
     76         </label>
     77         <span id="billTitle"></span>
     78     </li>
     79     
     80      <li>
     81         <label for="fa_piao">
     82               发票编号:
     83         </label>
     84           <input type="text" id="billCode" name="billCode"/>
     85     </li>
     86 
     87     <li>
     88         <label for="check_evidence">
     89             是否已开发票:
     90         </label>
     91         <input type="radio" id="isBill1" name="isBill" value="1"/> 92         <input type="radio" id="isBill0" name="isBill" value="0"/> 93     </li>
     94 
     95     <li>
     96         <label for="get_evidence">
     97             是否已领发票:
     98         </label>
     99         <input type="radio" id="isDrawBill1" name="isDrawBill" value="1"/>100         <input type="radio" id="isDrawBill0" name="isDrawBill" value="0"/>101     </li>
    102 
    103     <li>
    104     
    105         <label for="date">
    106             已发确认日期:
    107         </label>
    108         <span id="confirmDate"></span>
    109         <!-- <input type="text" id="confirmDate" name="confirmDate"/>  -->  
    110         <!--  <input id="confirmDate" name="confirmDate" class="text" type="text" onClick="WdatePicker()"/>  -->
    111     </li>
    112     <li>
    113         <label for="check_letter">是否已发确认函:</label>
    114         <span id="isConfirmInvitation"></span>
    115     </li>
    116      <li>
    117         <label for="fa_piao">在线支付状态:</label>
    118         <span id="payString"></span>
    119     </li>
    120     </ul>
    121     <div class="fee_opr">
    122         <button type="button" class="fee_sure" style="border: none;background: #003260;color: #ffffff;padding: 3px 30px;margin-left: 10px;border-radius: 0px;">确定</button>
    123         <button type="button" class="fee_cancel" style="border: none;background: #003260;color: #ffffff;padding: 3px 30px;margin-left: 10px;border-radius: 0px;">关闭</button>
    124     </div>
    125 </div>
    126 </form>
    View Code
    2、js代码:
     1  $(".fee_sure").click(function () {
     2         var dataObj = $("#costForm").serialize();
     3         var payType = $('input[name="payType"]:checked').val();
     4         if(payType == undefined){
     5             alert("请选择付款类型");
     6             return ;
     7         }else{
     8             $.ajax({
     9                 url:"/webCenter.do?method=saveUserMessage",
    10                 type: "post", 
    11                 dataType:"json",
    12                 data:dataObj,
    13                 cache:false,
    14                 ifModified:true,
    15                 success:function(json){
    16                         if(json.flag == 1){
    17                             alert("1234");
    18                         }
    19                 }
    20             })
    21         }
    22     })
    View Code

    3、后台action处理:

     1     @RequestMapping(params ="method=saveUserMessage",method=RequestMethod.POST)     //导入发言
     2                     public void saveUserMessage(int userId,HttpServletRequest request,HttpServletResponse response){
     3                         try {
     4                             HttpSession session  = this.getSession(request);
     5                             Adminuser adminUser = session.getAttribute("centerAdminUser") == null?null:(Adminuser) session.getAttribute("centerAdminUser");
     6                             if(adminUser == null){
     7                                 try {
     8                                     response.sendRedirect(request.getContextPath()+"/center/index.jsp");
     9                                 } catch (Exception e) {
    10                                     e.printStackTrace();
    11                                 }
    12                             }else{
    13                                 String billNumber =  request.getParameter("billCode")==null?"":request.getParameter("billCode");
    14                                 String isBaodao =  request.getParameter("baodao")==null?"0":request.getParameter("baodao");
    15                                 String haspay =  request.getParameter("pay")==null?"0":request.getParameter("pay");
    16                                 String payType =  request.getParameter("payType")==null?"0":request.getParameter("payType");
    17                                 String isFkpz =  request.getParameter("isReceiveProof")==null?"0":request.getParameter("isReceiveProof");
    18                                 String isYkfp =  request.getParameter("isBill")==null?"0":request.getParameter("isBill");
    19                                 String isYlfp =  request.getParameter("isDrawBill")==null?"0":request.getParameter("isDrawBill");
    20                                 JSONObject jsonObject = new JSONObject();
    21                                 //AdminuserConferences adminuserConferences = webService.getAdminuserConferences(adminUser.getAdminuserId());
    22                                 UserInfo userInfo = webService.getUserInfoById(userId);
    23                                 if(userInfo!=null)
    24                                 {
    25                                     jsonObject.accumulate("flag",1);
    26                                     ChcRegUser chcRegUser = webService.getChcRegUser(userId);
    27                                     if(chcRegUser!=null)
    28                                     {
    29                                         chcRegUser.setHasPay(Integer.parseInt(haspay));
    30                                         chcRegUser.setPayType(Integer.parseInt(payType));
    31                                         if(chcRegUser.getHasPay()-chcRegUser.getPay()==0)
    32                                         {
    33                                             chcRegUser.setStateType(1);
    34                                         }
    35                                         webService.saveObject(chcRegUser);
    36                                         userInfo.setIsBaodao(Integer.parseInt(isBaodao));
    37                                         userInfo.setIsFkpz(Integer.parseInt(isFkpz));
    38                                         userInfo.setBillNumber(billNumber);
    39                                         userInfo.setIsYlfp(Integer.parseInt(isYlfp));
    40                                         userInfo.setIsYkfp(Integer.parseInt(isYkfp));
    41                                         webService.saveObject(userInfo);
    42                                         jsonObject.accumulate("pay", chcRegUser.getPay());
    43                                         jsonObject.accumulate("haspay", chcRegUser.getHasPay());
    44                                     }
    45                                 }else {
    46                                     jsonObject.accumulate("flag",0);
    47                                 }
    48                                 writeJson(response, jsonObject.toString());
    49                             }
    50                         } catch (Exception e) {
    51                             e.printStackTrace();
    52                         }
    53                     }
    View Code
  • 相关阅读:
    SQLException:The server time zone
    Golang开发环境和环境变量搭建
    Docker Swanm集群配置
    .net 批量导出文件,以ZIP压缩方式导出
    【旧文章搬运】Windows句柄表分配算法分析(实验部分)
    【旧文章搬运】Windows句柄表分配算法分析(三)
    【旧文章搬运】Windows句柄表分配算法分析(二)
    【旧文章搬运】Windows句柄表分配算法分析(一)
    【旧文章搬运】PspCidTable攻与防
    【旧文章搬运】PspCidTable概述
  • 原文地址:https://www.cnblogs.com/jichuang/p/8031840.html
Copyright © 2011-2022 走看看