前端传值到后端使用base64 js编码 java解码 中文
js base64 编码 解码
Var text = ‘中文’;
//编码
text = encodeURI(text);
text = btoa(text);
//解码
text = atob(text);
text = decodeURI(text);
Java base64 编码 解码
使用org.apache.commons.codec.binary.Base64
Base64 base64 = new Base64();
//编码
String text = “中文”;
Byte[] textByte = text.getBytes(“UTF-8);
text = base64.encodeToString(textByte);
//解码
text = new String(base64.decode(text),”UTF-8”);
js编码 java解码
//编码
var text = “中文”;
text = encodeURI(text);
text = btoa(text);
//解码
text = new String(base64.decode(text),”UTF-8”);
text = URLDecoder.decode(text,”UTF-8”);
本文探讨了如何在前端使用JS进行Base64编码,并在后端Java环境中进行解码。通过org.apache.commons.codec.binary.Base64库,实现Java中的Base64操作,确保在中文字符处理上的正确性。
1万+

被折叠的 条评论
为什么被折叠?



