zoukankan      html  css  js  c++  java
  • springmvc jsp页面href传参中文乱码问题和数据类型问题

    jsp页面

    例1:href="${ctx}/custbill/toselectdetail?id=${bill.shopid}&tel=${bill.customertel}&projectid=${bill.projectid}&customername="+encodeURI(encodeURI("${bill.customername}"))

    例2:<a class="sub_bt_sm" id="${fundsList.num}${fundsList.num}" href="#" onClick="javascript:location.href='../funds/operating?applyId=${fundsList.applyId}&applyDirection=${fundsList.applyDirection}&businessName=' + encodeURI(encodeURI('${fundsList.businessName}')) + '&businessNumber=${fundsList.businessNumber}&applyMoney=${fundsList.applyMoney}&applyState=${fundsList.applyState}&applyUserId=${fundsList.applyUserId}&applyAccount=${fundsList.applyAccount}&applyBankName=' + encodeURI(encodeURI('${fundsList.applyBankName}')) ">申请处理</a>

    //页面encodeURI编码两次,解码一次   //参数为空时为'',不是null   所以int类型的值为null时会报请求错误,可以在后台用String接收

    Controller部分接收

    try {       //异常
    customername = URLDecoder.decode(customername, "UTF-8");
    //customername = new String(customername.getBytes("ISO-8859-1"),"UTF-8");           //解码
    tel = URLDecoder.decode(tel, "UTF-8");
    } catch (Exception ex) {
    }

    -----------------------------------------------------------------------------------------------------------------------------------------------------

    post中文乱码问题

    var customername = $("#customername", navTab.getCurrentPanel()).val();      //取值

    customername = encodeURIComponent(encodeURIComponent(customername));  //先编码再写进url

    后台解码

    try {
    customername = URLDecoder.decode(customername, "UTF-8");
    } catch (Exception ex) {
    }

    当能力支撑不了野心时,就该静下心来学习!
  • 相关阅读:
    Redis笔记 —— string 篇
    解决跨域请求无法携带Cookie的问题
    Mysql事务学习笔记
    Redis笔记 —— hash 篇
    mysql视图的简单学习
    axios无法被识别为ajax请求的解决方案
    常见header信息详解
    int 15h
    操作系统有进程了
    是时候走我自己的路线了,真正的做我自己的Jinux
  • 原文地址:https://www.cnblogs.com/1234cjq/p/5817472.html
Copyright © 2011-2022 走看看