lanxiazhi wrote:
hello,
I have a web app in tomcat ,where exists some .jsp,.vm files,
these files are saved using different encoding(I think).when requested,some
of them display urgly,garbled.
so I think maybe I can implement such a filter:first read the content of the
file,and* *decide which charset it's saved,and set the ServletResponse's
character encoding accordingly.
Is that possible ? If possible ,how to decide the charset quickly ,without
slowing down the server?
thanks
lanxiazhi


Answering your last question first : that is close to impossible.
It is not even the question of slowing down the server, it is really that detecting the charset is not possible in a number of cases.
Very shortly :
- it is is usually possible to detect if a given file is valid UTF-8 or not.
- but it is not possible to decide if a file encoded in an 8-bit alphabet (such as iso-8859-1) is iso-8859-1 or iso-8859-2 or any other 8-bit character set (because they all use bytes with a value between \x00 and \xFF, so how can you decide ?).

Given this, your best bet is to correct the problem at the source :
Any text file, in any original encoding, can be converted to UTF-8/Unicode. So clean up the original files, and always send them back as UTF-8. All reasonably recent browsers support that.



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to