足球游戏_中国足彩网¥体育资讯$

html 中文乱码 HTML超链接中文乱码问题分析及解决方法
来源:易贤网 阅读:1786 次 日期:2016-06-21 14:15:37
温馨提示:易贤网小编为您整理了“html 中文乱码 HTML超链接中文乱码问题分析及解决方法”,方便广大网友查阅!

Vm中一个超链接URL需要拼接中文作为Get请求的参数。如果直接拼接,传到后台Action的参数对象中后取出会是乱码,需要编码后再拼接到URL上。

解决方法是在Action中添加一个成员变量,保存编码后的中文参数。在vm页面渲染时取出这个变量值,再拼接超链接。

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

代码如下:

/**

* Translates a string into <code>x-www-form-urlencoded</code>

* format. This method uses the platform'sdefault encoding

* as the encoding scheme to obtain thebytes for unsafe characters.

*

* @param s <code>String</code> 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 <code>String</code>.

*/

@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)方法依赖于平台字符集。

中国足彩网信息请查看网页制作
由于各方面情况的不断调整与变化,易贤网提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!
关于我们 | 联系我们 | 人才招聘 | 网站声明 | 网站帮助 | 非正式的简要咨询 | 简要咨询须知 | 加入群交流 | 手机站点 | 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 足球游戏_中国足彩网¥体育资讯$ 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:hfpxwx
咨询QQ:526150442(9:00—18:00)版权所有:易贤网
云南网警报警专用图标