手机
当前位置:查字典教程网 >网页设计 >XHTML >html 中文乱码 HTML超链接中文乱码问题分析及解决方法
html 中文乱码 HTML超链接中文乱码问题分析及解决方法
摘要:Vm中一个超链接URL需要拼接中文作为Get请求的参数。如果直接拼接,传到后台Action的参数对象中后取出会是乱码,需要编码后再拼接到UR...

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

【html 中文乱码 HTML超链接中文乱码问题分析及解决方法】相关文章:

div被iframe遮住的几种情况及解决方法

xhtml css网页制作问题的解决方法

关于表格table嵌套,边框合并问题的解决方法

html中设置锚点定位的几种常见方法

HTML中当定义多个class属性时无效的解决方法

设置frameset的高度 界面变形的解决方法

html select标签加链接3种方法

HTML中select下拉框内容显示不全部分被覆盖的解决方法

html中使用margin:0 auto整个页面不居中的解决方法

HTML 结构化实现方法

精品推荐
分类导航