工具插件下载地址http://download.youkuaiyun.com/detail/jokewangloveyou/6613719
<script src='http://code.jquery.com/jquery-1.9.1.min.js'></script>
<script src='jquery.base64.js'></script><script>
var dec = $('#decode'),
enc = $('#encode');
// you can set utf8 encoding and decoding via global option
// possible options:
// `utf8encode` - utf8 encoding only (default: `false`)
// `utf8decode` - utf8 decoding only (default: `false`)
// `raw` - both (default: `true`)
$.base64.utf8encode = true;
enc.keyup(function () {
dec.val($.base64.btoa(this.value));
// also possible:
// dec.val( $.base64('encode', this.value) );
// dec.val( $.base64.encode(this.value) );
});
dec.keyup(function () {
// note: you can pass a third parameter to use the utf8 en- / decode option
enc.val($.base64.atob(this.value, true));
// also possible:
// dec.val( $.base64('decode', this.value) );
// dec.val( $.base64.decode(this.value) );
});
$('textarea').on('focus blur', function () {
$(this).prev('label').stop().fadeToggle(200);
});
$("#bar_save").click(function (){
var obj = Model.define;
//alert("保存");
var str = JSON.stringify(obj);
$.base64.utf8encode = true;
var data = "jsonParams="+$.base64.btoa(str);
//alert(chartId);
//console.log(JSON.stringify(definition));
console.log(str);
console.log($.base64.atob($.base64.btoa(str),true,'utf8'));
$.ajax({
type: "POST",
url: "../coeTeamPalDesignerImageServlet.wf?&uuid="+chartId,
data: data,
success: function(msg){
}
});
});
</script>
后台java解码
private static String getFromBase64(String str) {
if (str == null) {
return "";
}
BASE64Decoder decoder = new BASE64Decoder();
try {
byte[] b = decoder.decodeBuffer(str);
return new String(b,"utf-8");
} catch (Exception e) {
e.printStackTrace();
}
return "";
}