使用java在网页中进行字符编码 [英] character encoding in a web page using java

查看:149
本文介绍了使用java在网页中进行字符编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用java找出网页中的字符编码类型

how to find out the type of character encoding in a web page using java

推荐答案

打开与URL的连接(使用 URL.openConnection()),解析 getContentType()方法(应该包含charset)。如果此标头中没有,您可能需要解析HTML内容并查找标签,例如

Open a connection to the URL (using URL.openConnection()), adn the parse the content type returned by the getContentType() method (which should contain the charset). If not present in this header, you might have to parse the HTML content and look for a tag such as

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

这篇关于使用java在网页中进行字符编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆