//js代码 str为密码参数 function chr2Unicode(str) { if ('' != str) { var st, t, i; st = ''; for (i = 1; i <= str.length; i ++){ t = str.charCodeAt(i - 1).toString(16); if (t.length < 4) while(t.length <4) t = '0'.concat(t); t = t.slice(2, 4).concat(t.slice(0, 2)) st = st.concat(t); } return(st.toUpperCase()); } else { return(''); } } 后台代码: /** * 将Unicode转回GBK形式 * @param beginIndex the beginning index, inclusive. * @param endIndex the ending index, exclusive. * @return the specified substring. * @exception */ public String UnicodeToGBK(String str){ String st="", t=""; try { if ("" != str) { int i; st = ""; for (i = 1; i <= str.length()/4; i ++){ t = str.substring(4*i-4, 4*i-2); t = str.substring(4*i-2, 4*i).concat(t); st = st.concat("%u").concat(t); } st = unescape(st); return st; }else{ return ""; } } catch (Exception e) { throw new Exception("密码转换出错!",e); } } 这样就完成了一个客户端到服务器之间的密码加密的过程。