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

[477 byte] By [nskarthik_ka] at [2007-11-27 10:46:45]
# 1

Hi

Do any has any advise plz

with regards

Karthik

nskarthik_ka at 2007-7-28 20:20:42 > top of Java-index,Java Essentials,Java Programming...
# 2

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.

malcolmmca at 2007-7-28 20:20:42 > top of Java-index,Java Essentials,Java Programming...
# 3

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

nskarthik_ka at 2007-7-28 20:20:42 > top of Java-index,Java Essentials,Java Programming...
# 4

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.

malcolmmca at 2007-7-28 20:20:42 > top of Java-index,Java Essentials,Java Programming...
# 5

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

nskarthik_ka at 2007-7-28 20:20:42 > top of Java-index,Java Essentials,Java Programming...
# 6

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.

malcolmmca at 2007-7-28 20:20:42 > top of Java-index,Java Essentials,Java Programming...
# 7

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

nskarthik_ka at 2007-7-28 20:20:42 > top of Java-index,Java Essentials,Java Programming...
# 8

You shouldn't need to, and you can't expect all your site's users to muck about with browser settings. AFAIK all serious browsers will accept UTF-8 (Check the "Page Info" when your form is presented).

malcolmmca at 2007-7-28 20:20:42 > top of Java-index,Java Essentials,Java Programming...