HTML超链接中文乱码怎么解决

来源:爱站网时间:2020-12-09编辑:网友分享
我们在HTML中经常会遇到HTML超链接中文乱码的问题,因此难倒了不少用户们,那么你知道HTML超链接中文乱码怎么解决吗?下面我们就一起去看看吧。

我们在HTML中经常会遇到HTML超链接中文乱码的问题,因此难倒了不少用户们,那么你知道HTML超链接中文乱码怎么解决吗?下面我们就一起去看看吧。

Vm中一个超链接URL需要拼接中文作为Get请求的参数。如果直接拼接,传到后台Action的参数对象中后取出会是乱码,需要编码后再拼接到URL上。
解决方法是在Action中添加一个成员变量,保存编码后的中文参数。在vm页面渲染时取出这个变量值,再拼接超链接。

在这里碰到的问题是:调用java.net.URLEncoder的encode()方法时,如果没有显示指定字符集参数,那么URLEncoder会使用默认字符集。这个默认字符集在Eclipse里跑main()方法和在Tomcat里跑Web应用,得到的结果不一样,所以影响了编码的结果。
 

复制代码
代码如下:

/**
* Translates a string into x-www-form-urlencoded
* format. This method uses the platform'sdefault encoding
* as the encoding scheme to obtain thebytes for unsafe characters.
*
* @param s String to betranslated.
* @deprecated The resulting string mayvary depending on the platform's
* default encoding. Instead, use theencode(String,String)
* method to specify the encoding.
* @return the translated String.
*/
@Deprecated
public static String encode(String s) {
String str = null;
try {
str = encode(s, dfltEncName);
} catch(UnsupportedEncodingException e) {
// The system should always have theplatform default
}
return str;
}


方法的注释中也说明了不建议使用的原因是,这个encode(String)方法依赖于平台字符集。

看完本文后你知道HTML超链接中文乱码怎么解决了吗?希望对大家有所帮助,欲了解更多资讯请登录爱站技术频道网站了解,在此小编非常感谢大家对爱站技术频道网站的支持!

上一篇:把select下拉框的值传到id中实现方法

下一篇:HTML网页页面的基础知识

您可能感兴趣的文章

相关阅读

热门软件源码

最新软件源码下载