javascript向后台传递中文参数乱码

1.通过url传递参数,通过两次编码,在后台进行一次解码:

   前台:

   searchWords = encodeURI(searchWords);
   searchWords = encodeURI(searchWords);

 

   后台java:

   searchWords = URLDecoder.decode(searchWords, "UTF-8");

 

2.通过ajax提交参数,通过一次编码,在后台进行一次解码:

   前台:

   searchWords = encodeURI(searchWords); 

   后台java:

   searchWords = URLDecoder.decode(searchWords, "UTF-8");

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(JavaScript,javascript,java,ajax,url)