get提交中文乱码问题
2016-03-01 14:07
211 查看
最近,因为在维护的一个项目,在页面用自定义标签get方式提交,所以在页面输入关键字提交到后台的时候,会有乱码的现象,所以写文章,为了下次更方便的使用。主要是使用了Base64
jsp页面代码片段
jsp页面代码片段
<c:set var="brandAcceptParam" value="encodeKeyWords,attrs,clsId,promotion,brandId,begPrice,endPrice,fsop,searchTag,services,local,listingTags"/>
<a href="<search:urlTag actionUrl='/search.do'acceptParamNames="${brandAcceptParam}"/>">分类名</a>
<form name="thumbsearch" action="/item/search.do" method="post"> <input type="hidden" name="encodeKeyWords" value="${encodeKeyWords}"/> <input type="text" name="keywords" placeholder="在当前位置下搜索" value="${keywords!=null?keywords:''}"/> <button type="submit">搜索</button> </form>
/** 对字符串参数进行base64编码 */ public static String seoUrlBase64Encoder(String value){ if(value == null) return null; BASE64Encoder encoder = new BASE64Encoder(); try { value = encoder.encode(value.getBytes("utf-8")); value = value.replaceAll("[\r\n]", "").replaceAll("/", "_");//BASE64Encoder的encode方法会在76个字符后添加\r\n value = value.replace(' ', '+'); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return value; }
/** 对字符串参数进行base64解码 */ public static String seoUrlBase64Decoder(String value){ if(value == null) { return null; } String str = null; BASE64Decoder decoder =new BASE64Decoder(); try { value = value.replace(' ', '+'); value = value.replaceAll("_", "/"); str = new String(decoder.decodeBuffer(value),"utf-8"); str = str.trim(); } catch (IOException e) { e.printStackTrace(); } return str; }
相关文章推荐
- MySQL常用时间函数
- 2016-03-01 地图定位 以及失败
- Android APP 开发项目框架搭建
- NGUI点透问题
- ZOJ1041
- 阻止ie、chrome中的事件冒泡和监听函数的覆盖问题
- 个人简介
- beanstalkd----安装启动
- .NET Framework个版本说明
- 自定义线程池ThreadPoolExecutor
- 解决国内ruby gem不能用的问题
- VMware中Bridged、NAT、host-only三种网络连接模式的原理及其区别
- strcasecmp()和strncasecmp()比较
- Java程序员修炼之道 之 Logging(3/3) - 怎么分析Log
- 如何通过ZBrush中的套索工具绘制遮罩
- 使用 Github 的图片版本比较
- redis 五种数据类型的使用场景
- kafka原理解析-《Learning Apache Kafka, 2nd Edition.pdf》
- 静态/动态注册广播的区别,静态动态广播区别
- 内核基础 - 寄存器与内存寻址(by quqi99)