您的位置:首页 > 其它

get提交中文乱码问题

2016-03-01 14:07 211 查看
最近,因为在维护的一个项目,在页面用自定义标签get方式提交,所以在页面输入关键字提交到后台的时候,会有乱码的现象,所以写文章,为了下次更方便的使用。主要是使用了Base64

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;
}






                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: