html 中文html汉字乱码问题题

为什么HTML写的代码,中文显示是乱码
[问题点数:40分]
为什么HTML写的代码,中文显示是乱码
[问题点数:40分]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
匿名用户不能发表回复!|html 中文乱码 HTML超链接中文乱码问题分析及解决方法
互联网 & 12-30 16:54:52 & 作者:佚名 &
Vm中一个超链接URL需要拼接中文作为Get请求的参数如果直接拼接,传到后台Action的参数对象中后取出会是乱码,需要编码后再拼接到URL上,接下来将和大家分享一下解决方法
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 = try { str = encode(s, dfltEncName); } catch(UnsupportedEncodingException e) { // The system should always have theplatform default }
} 方法的注释中也说明了不建议使用的原因是,这个encode(String)方法依赖于平台字符集。
大家感兴趣的内容
12345678910
最近更新的内容1.中文乱码的成因
编码的字符集和解码的字符集不一致。
2.web开发过程中可能出现的乱码的位置及解决方案
①request乱码
在向服务器传递数据时,所传递的中文有可能出现乱码。
post请求(协议体)
解决:request.setCharacterEncoding("UTF-8");
get请求(地址栏)
解决:需要在 tomcat 中进行额外的配置(本人使用的是tomcat服务器)。
tomcat 的 conf/server.xml 中配置如下代码即可:
connectionTimeout="20000"
redirectPort="8443"&
URIEncoding="UTF-8"
②response乱码
响应给客户端的动态网页中如果出现中文有可能出现乱码。
response.setCharacterEncoding("UTF-8");
response.setContentType("text/charset=UTF-8")
感谢您的支持,我会继续努力的!
扫码打赏,你说多少就多少
记住登录状态
重复输入密码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 = try { str = encode(s, dfltEncName); } catch(UnsupportedEncodingException e) { // The system should always have theplatform default }
} 方法的注释中也说明了不建议使用的原因是,这个encode(String)方法依赖于平台字符集。
欢迎转载:
相关推荐:

我要回帖

更多关于 html 乱码 中文汉字 的文章

 

随机推荐