Cp1252 characters not read when submitted from Internet Explorer
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Parag_Doshi
Posted On:   Saturday, February 21, 2004 01:36 AM

Hi I am facing this problem of characters not being passed on to the server side when form is submitted using IE 6.0 browser. I have tried printing the characters entered by the user using javascript and they show up fine. Strangely, the same form submitted from Netscape 7.1 browser is being properly read and saved in the database. I have set the content type to Cp1252 using the response object response.setContentType("text/html; charset=Cp1252"); My environment is - Sun Solaris OS - Apache 1.3.27 web server - Tomcat 3.3.1a JSP container - jdk1.3.1_01    More>>


Hi



I am facing this problem of characters not being passed on
to the server side when form is submitted using IE 6.0
browser. I have tried printing the characters entered by the
user using javascript and they show up fine.



Strangely, the same form submitted from Netscape 7.1 browser
is being properly read and saved in the database.



I have set the content type to Cp1252 using the response
object response.setContentType("text/html; charset=Cp1252");



My environment is


- Sun Solaris OS


- Apache 1.3.27 web server


- Tomcat 3.3.1a JSP container


- jdk1.3.1_01



Is there some kind of setting / configuration that needs to
be done on the IE side or is it some setting on the tomcat
side that needs to be tweaked for getting the correct
values. Tried resetting the option "Always send URL as UTF-8", but same result.



I tried my application using JRun 4.0, but still got the
same result. The russian characters are being read properly
when submitted from Netscape 7.1, but show as weird
characters when submitted from Internet Explorer 6.0



Appreciate any help on this problem.



Thanks,
parag    <<Less

Re: Cp1252 characters not read when submitted from Internet Explorer

Posted By:   Stephen_Ostermiller  
Posted On:   Saturday, March 20, 2004 06:28 AM

You also need to do a request.setCharacterEncoding("Cp1252") before you use the request.getParameter() method.


The getParameter() method does URL decoding and needs to know the character set to use when doing so.


Alternatly, you may want to use UTF-8 rather that Cp1252 since it can handle more characters and is more portable.

Re: Cp1252 characters not read when submitted from Internet Explorer

Posted By:   Parag_Doshi  
Posted On:   Monday, February 23, 2004 10:12 PM

Here are the three javascript functions that do the job

for converting the data into the base-10 characterset

from a unicode characterset. You need to pass the object

of the text field to the convertToUnicodeToBase10

function.



regards,

parag



--------8<--------8<--------8<--------8<--------8<--------8<--------8<--------8<--------8<--------8<

/*

Function that takes an object as a parameter

and converts the string to a unicode and then

to base 10 to support internationalization

*/

function convertToUnicodeToBase10(obj)

{

/*

For Internet Explorer convert the string entered in russian

to unicode characters (%uXXXX) and then convert the hexadecimal

to base-10 and replace the value

*/

if (navigator.appName.indexOf("Microsoft") != -1)

{

var escStr;

var decStr;


escStr = escape(obj.value);

var strlen = escStr.length;

decStr = new Array();


/*

For every character in the escpaed (converted to

unicode, if the first two characters are %u, then

convert to decimal. The escpae function converts

spaces or special characters to %20, %xx, etc. This

needs to be appended to the decimal string as is.

For plain english characters, just append the

character to the string.

*/

for (t=0; t
{

/*

alert("value of t");

alert(t);

alert(escStr.substring(t,t+1));

alert(escStr.substring(t+1,t+2));

*/

if (escStr.substring(t,t+1) == "%") // is the first character a %

{

if (escStr.substring(t+1,t+2) == "u") // is the second character a u

{

/*

alert("string has %u");

alert(toDecimal(escStr.substring(t+2,t+6)));

*/

decStr += "&#" + todecimal(escstr.substring(t+2,t+6));

t+=5;

}

else // this is a uuencoded space or special string

{

decStr += escStr.substring(t,t+3);

t+=2;

}

}

else

{

decStr += escStr.substring(t,t+1);

}

//alert(decStr);

}

/*

need to unescape the string to remove space and

other special characters

*/

decStr = unescape(decStr);

//alert(decStr);

obj.value=decStr;

}

}



/*

Function that takes a hexadecimal number and

converts it to decimal by doing a left shift

of 12, 8 and 4 on the first three characters

of the string.

*/

function toDecimal(hexNum)

{

var tmp = hexNum.toUpperCase();

return ((deHex(tmp.substring(0,1)) << 12) +

(deHex(tmp.substring(1,2)) << 8) +

(deHex(tmp.substring(2,3)) << 4) +

(deHex(tmp.substring(3,4))));



}



/*

function that returns the hexadecimal value
of a decimal number

*/

function deHex(aDigit)

{

return("0123456789ABCDEF".indexOf(aDigit))

}

--------8<--------8<--------8<--------8<--------8<--------8<--------8<--------8<--------8<--------8<
About | Sitemap | Contact