permaculture playing cards*
The moose likes Other JSE/JEE APIs and the fly likes Unable to read charset using java.net.URLConnection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Reply locked New topic
Author

Unable to read charset using java.net.URLConnection

Rudy B Baylor
Greenhorn

Joined: Oct 02, 2007
Posts: 6
Using java.net package, I am trying to read a html page, which has Content-Type as



Now it is very critical for me to be able to read the charset which is mentioned in tag above.

Using urlConnection.getContentType(), urlConnection.getHeaderField("Content-Type") just returns "text/html", which I believe is because the above methods derive value from some other place rather than the <meta> tag shown above.

Is there a way of getting the values of <meta> tags beforehand so that one can determine what charset to use while reading ?.

I need to read a html page and write that to a already initialized response object. For that it is critical for me to determine the encoding of the html file.

Transferring bytes directly from InputStream to response OutputStream, irrespective of encoding, is not working as the response.getWriter() has already been called and hence response.getOutputStream() throws IllegalStateException !!!.

Someone please advise ways to resolve the problem.

Thanks in advance
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

Please do not post the same question more than once. It causes confusion and duplication of effort as the community tries to help everyone.
CarefullyChooseOneForum


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to read charset using java.net.URLConnection