处理URL中文参数问题,对中文参数进行编码和解码

import org.apache.commons.codec.base64.Base64;
/**
* 提供对 URL 进行处理的工具类
*/
public class URLUtil
{
/**
* 将 URL 参数据进行安全编码
* @param s
* @return
*/
public final static String safeRequestParameter(String s)
{
byte[] b = Base64.encode(s.getBytes());
StringBuffer sb = new StringBuffer();
for(int i = 0; i < b.length; i++) { sb.append("%" + Integer.toHexString(b[i])); } return sb.toString(); } /** * 对 URL 参数据进行安全解码 * @param s * @return */ public final static String decodeSafeRequestParameter(String s) { return new String(Base64.decode(s.getBytes())); } }

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理

相关文章

开始在上面输入您的搜索词,然后按回车进行搜索。按ESC取消。

返回顶部