cancel
Showing results for 
Search instead for 
Did you mean: 

PageEncoding

Former Member
0 Kudos

How can I set the default page encoding for the MI? In my own application the MI always returns a header containing:

Content-Type: text/html;charset=ISO-8859-1

even though the top entry in my JSP is:

<%@page contentType="text/html; charset=UTF-8" %>

Thanks for your help.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Peter

You cannot change the default page encoding of MI. Even though you have used charset as UTF-8 in your JSP files, what is returned is always ISO-8859-1 standard. It is not MI that does this conversion. It could either be the underlying server (say tomcat) or it is a standard specification that if UTf-8 is mentioned in JSP as the charset, then all the texts like String etc come to your application only in ISO-8859-1 format. I faced this problem recently and the way i resolved this problem is by making use of the folowing code. This method takes a input string in ISO-8859-1 format and then returns the same string in UTF-8 format. Hope this would be of help to you in your application.

public final static String ConvertISO8859toUTF8(String stringToBeConverted) {
	String UTF8ConvertedString = "";
	try {
		byte[] bytes_ISO8859 = stringToBeConverted.getBytes("ISO-8859-1");
		UTF8ConvertedString = new String(bytes_ISO8859, "UTF-8");
	} catch (UnsupportedEncodingException e) {
	               System.out.println("Encoding format not supported");
	}
	return UTF8ConvertedString;
}

Best Regards

Sivakumar

Former Member
0 Kudos

Hello,

If you use CAF you can use the processEncoding method in FrontServlet to do that kind of stuff.

Thank you,

Julien.

Former Member
0 Kudos

Thanks for your replies so far.

What really irritates me is that the "me" app from the SAP itself - always returns UTF-8 correctly. So this somehow must be coded somewhere that other own apps have ISO-8859-1 even if I do not have it anywhere any more in my sources.

Former Member
0 Kudos

Hello,

What we are telling you is that you can display the page as UTF-8 (as the me app or MAM), but when the page data comes back to the server (your app then) it is encoded in ISO. I don't know which part breaks the UTF-8 but I would say the Internet Explorer does (always blame IE).

In MAM, I personnaly implemented the conversion as stated in another message. It's working well.

Thank you,

Julien.

Answers (2)

Answers (2)

Former Member
0 Kudos

hi peter,

there are 2 ways to set your servlet's HTTP response encoding:

- using ServletResponse.setContentType

e.g. response.setContentType("text/html;charset=UTF-8");

- using ServletResponse.setLocale

to set HTTP headers for the given locale ( including the charset)

now in your JSP, this directive will be translated to the response.setContentType

in the generated source code.

<%@ page contentType="text/html;charset=UTF-8" %>

note of the space between @ and page.

i think PocketIE doesn't recognize UTF-8 rather it should be specified as UTF8.

however, im not sure the latest version. this might have been fixed already.

regards

jo

Former Member
0 Kudos

Hi,

If you want use a encode/decode in jsp, use this functions before do a submit.

[code]

function url_encode(str) {

var hex_chars = "0123456789ABCDEF";

var noEncode = /^([a-zA-Z0-9\_\-\.])$/;

var n, strCode, hex1, hex2, strEncode = "";

for(n = 0; n < str.length; n++) {

if (noEncode.test(str.charAt(n))) {

strEncode += str.charAt(n);

} else {

strCode = str.charCodeAt(n);

hex1 = hex_chars.charAt(Math.floor(strCode / 16));

hex2 = hex_chars.charAt(strCode % 16);

strEncode += "%" + (hex1 + hex2);

}

}

return strEncode;

}

function url_decode(str) {

var n, strCode, strDecode = "";

for (n = 0; n < str.length; n++) {

if (str.charAt(n) == "%") {

strCode = str.charAt(n + 1) + str.charAt(n + 2);

strDecode += String.fromCharCode(parseInt(strCode, 16));

n += 2;

} else {

strDecode += str.charAt(n);

}

}

return strDecode;

}

[/code]

Thanks

Former Member
0 Kudos

Thanks all for your help. In the end it turned out to be a problem in a taglib we were using that modified the encoding. In addition the SAP support gave us wrong answers which lead to big confusion. What I wrote in my initial post will work to set the page encoding and server headers to UTF-8.

Thanks for the postings above regarding the data concversion.

Former Member
0 Kudos

Hello,

I usually add the following to my HTML:

<META http-equiv="Content-Type" content="text/html; charset=utf-8">

Julien.