特殊符号 -以及转义(初 笔记)

xiaoxiao2021-02-28  31

1.后台到页面 若是有特殊符号,是不能够被当做参数传入方法、超链接、input的value

EL${}表达式不能传特殊符号,要用<c:out></c:out>

页面代码如下:

<a href="javascript:void(0);"  οnclick="formKhhhid('<c:out value='${khhhdaxxb.khhhid}'></c:out>')">${khhhdaxxb.khhh}</a>

当做超链接参数传入后台的时候replace方法:

var str   =                                                                                                                                                                                khhhid.replace(/\"/g,'"').replace(/\#/g,'#').replace(/\'/g,''').replace(/\?/g,'?').replace(/\&/g,'&').replace(/\=/g,'=');

location.href ="${ctx}/yhxx/khhhdaxxb/form?khhhid="+str+"";

后台传入的时候用StringEscapeUtils.unescapeHtml4()方法转义

代码:

return khhhdaxxbService.get(StringEscapeUtils.unescapeHtml4(khhhid));

 

2.2018-10-19补充  js中处理特殊符号的方法encodeURIComponent();

可以替代上叙 

var str   =                                                                                                                                                                                khhhid.replace(/\"/g,'"').replace(/\#/g,'#').replace(/\'/g,''').replace(/\?/g,'?').replace(/\&/g,'&').replace(/\=/g,'=');

 

----------转义-------

1.前端    

  $("#"+sbid)..append("<p class='zcd' οnclick='qhdt(this,\""+ cs1+""+sf+""+ cs2 +"\",\""+sbid+"\")'>"+ jslmc +"</p>");

 

ajax 提交中文参数乱码

1. 用encodeURI()方法包2次参数

2.后台用URLDecoder.decode(参数, "UTF-8")方法得到中文参数

如:

    url : "${ctx}/zbsys/qdjm/saveZbpbxqb?zbpbxqbid="+zbpbxqbzbid+"&bz="+encodeURI(encodeURI(bz)),

    zbpbObject.setBz(URLDecoder.decode(bz, "UTF-8"));

 

转载请注明原文地址: https://www.6miu.com/read-2624084.html

最新回复(0)