on 01-22-2007 2:09 PM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.
Hello,
I usually add the following to my HTML:
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
Julien.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.