java后台与jsp前台特殊字符处理(字符串编码与解码)

在后台与前台数据交互时如果有特殊字符就很容易出现问题,所以就需要对字符串进行编码传输,在获取后再进行解码:

1.Java后台进行编码与解码

URLEncoder.encode(str,"utf-8");//编码

URLDecoder.decode(str,"utf-8");//解码

2.jsp页面进行编码解码

encodeURI(str);//编码

encodeURIComponent(str);//编码

decodeURI(str);//解码

decodeURIComponent(str);//解码

原文地址:https://www.cnblogs.com/henuyuxiang/p/7307278.html