1. 程式人生 > >jsp開發中中文傳值加密解密,解決亂碼問題

jsp開發中中文傳值加密解密,解決亂碼問題

一:

頁面使用js加密:

user = window.encodeURI(user);

user = window.encodeURI(user);

document.location.href = "/communion.do?action=updateSpace&id=" + id + "&user=" + user;

其中user為中文,注意:一定要加密兩次;

二:

java程式碼解密:

String user = java.net.URLDecoder.decode(request.getParameter("user"),"UTF-8");

解密;

三:

轉碼:

private String convert(String str) throws UnsupportedEncodingException {

return new String(str.getBytes(),"GBK");

}