For e.g me & myself. However, this data saves correctly in our database, but the display on the web page ignore second space after me. So it's like me & myself. But when you view source, the data is there correctly. Upon further research, it's learnt that most browsers ignore extra white space and hence HTML spec introduced  . So in order to correct this issue any field that will have extra white spaces need to be encode by replacing spaces with  . Here is some reading on it to refresh my memory.
Source is from
http://www.theserverside.com/discussions/thread.tss?thread_id=28944
I know this is an annoying problem. Internet is a global thing, involving all languages, charsets, encodings and locales etc., but in my view the matter is underrepresented and there are no clear well known strategies. Most books, articles etc. silently assume that the world consists of English-speaking people... at most including a few French, Germans etc...
Anyway back to your problem:
I am trying to recollect from my memory, but if these advices don't work, please let me know and I will check the details of my own solution:
There are a few "intersections" where data is exchanged and where "implicit" encoding conversion might happen:
1- your mySQL DB: what version is it? Starting with 4.0.18 (I think) it can store UNICODE.
Prior to that you have to use binary columns to hold the data and prevent automatic conversion by MySQL.
2- I assume you fetch your data from JSP using JDBC. What driver (version) do you use?
3- the JDBC driver usually converts the data from the database automatically, depending on the default encoding of the machine it is running on.
To force JDBC to retrieve the data as unicode please use the parameter charset=utf8 (I don't have the exact synthax now... but you can check it yourself).
4- in the JSP page itself:
you have 2 levels of charset processing to deal with:
a- the java processing in the jsp-servlet itself, before data is sent back to the browser.
Here you have to take care that teh jsp-java code is not "silently converting" your data to the default charset, which might be "iso-8859-1" or anything that is not utf-8.
b- the 2nd level of data encoding is what is sent to the browser and how to force or help the browser to understand what "Character ENcoding" to use.
Well here you have of course to use ""
This is what has worked for me:
<%@ page
language="java"
contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"
%>
Bla bla bla ....
....
PS:
I found in my case that
contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"
is not creating the a HTML meta element ()
the only secure way to have that meta element in your resulting HTML code is to put in the source code of your JSP page (in the HTML source code)
So include always this:
to force the browser to handle & display it as UTF-8.
Most of code is tested on Tomcat 4, Websphere 5, 5.1 and JBoss 3.2.x & 4.
-----------------------------------------------------------------------------
So bottom line is:
1- Judging from your description your code is correct since you are seeing your correct content in the source page.
So the pint is whether you have this in your resulted HTML code:
""
Or check whether your HTML code is valid.
2- if that all is not solving your problem, the other strategy is to check in all those data-intersections whether your content is not tempered with (implicit coversions by your system...).
One of my colleagues resolved this using a specific style.
or alternatively..
No comments:
Post a Comment