jsp传中文乱码问题 encodeURIComponent()编码方法

方法一:

jQuery.ajax({
            type:"POST",
            url:"${ctx}/offer.do",
            data:{
                'method':'isNameExist',
                'type':'area',
                'id':id==""?null:id,
                'name':encodeURIComponent(offerAreaName)
            },
            async:false,
            success:function (data) {
                bool = data;
            }
        });

 

action里特别设置:

String offerAreaName= request.getParameter("offerAreaName");
  if(StringUtils.isNotEmpty(offerAreaName)){
     productName = new String(offerAreaName.getBytes("iso8859-1"),"UTF-8");
  }

 

方法二:

window.encodeURI(window.encodeURI(strBuf)) 编译后在传

 

处理方法中(action 或者 service):

try {
   strBuf= java.net.URLDecoder.decode(strBuf,"UTF-8");
  } catch (UnsupportedEncodingException e) {
   e.printStackTrace();
  }

posted @ 2014-06-13 18:56  【云】风过无痕  阅读(1274)  评论(0编辑  收藏  举报