UTF encodings in jsp Please ...:(
Hi Form
For an Web application ( jsp's ), I would like to have UTF-8 settings to be
handled
1) <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
2) request.setCharacterEncoding("utf-8");
response.setContentType("utf-8");
3) <%@page contentType="text/html;charset=UTF-8"%>
Should i include all of this in my jsp or any of these alone would do ?
Please advise me
with regards
karthik
There are two aspects, sending data is controlled by the contentType, but if you read parameters from the request you need to set the encoding there too. The pageEncoding attribute of the page tag should do this or you can do request.setCharacterEncoding.
You can use the meta element but it shouldn't be necessary. The browser should get the encoding from the http headers.
Hi
Thx for the reply
But still in delimaa
My appication of JSP in here uses a static Content display read from a flat
file from a folder , This static content flat file
is as per language changeable.
So can u advise more on this type of usage , What settings of UTF need to
be used (1,2, or 3)
with regards
Karthik
If you are copying it with code, then you need to use a Reader with the encoding coresponding to how the text is stored in the resource file (use InputStreamReader). The writer in the JSP page should automatically take it's encoding from the page directive.
You should probably be using a custom tag library for things like this, scriptlets (java code in JSPs) should be kept to a minimum.
Hi
Thx again for the advise
U mean to say
"<%@page contentType="text/html;charset=UTF-8"%>"
This should take care of the solution.
If in such a case, Can i instead set this in a common header file and
import the same in all the other pages of my JSP.
Do u think this would work
Please advice for the last time
with regards
Karthik
Probably, if you used a <@ include tag to load the fragment, but I wouldn't advise it since the <@ include would be almost as long as the <@page directive, and far more confusing.
Hi
One final Question ,I forgot to ask
I have found so many forms which claim to help utf settings / code
sample.
but non of these worked
Should i still set the browser ( FIREFOX / IE6 ) settings
to UTF -8 inspite of the code settings in JSP is set to
UTF-8 ?
With regards
Karthik