I'd like to encode a string from "UTF-8" to "cp1252" with JavaScript.
I have an HTML document sent as utf-8, and in that document there is a hidden field keep the JsonString which contain "UTF-8" characters such as "二". My Java Bean doesn't receive the correct value on the server-side, it gets "?".
<h:inputHidden id="hiddenPropertiesValues"
value="#{Bean.newProperties}"/>
Java Bean class sscce
public void setNewProperties( String newProperties ) {
this.newProperties = newProperties;
}
I tried to trans-code the JsonString to "cp1252" by java code first. And then input the trans-coded JsonString to the hidden field. The Bean can get the correct characters.
So I thought I can solve this problem by encoding the string from "UTF-8" to "cp1252" with JavaScript.
Both of the Html and the Java Bean files use "UTF-8".