dcsimg
8859-1 to UTF-8 conversion and platform default charset
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Yogesh_Kumar
Posted On:   Wednesday, August 15, 2007 08:01 PM

Hi, I have a JSP with UTF-8 page encoding (I have charset=UTF-8"> in HTML head). This JSP receives form data from external website which are encoded in ISO-8859-1. I have set request.setCharacterEncoding("ISO-8859-1"); in the beginning before getting parameter. I am trying to convert these ISO-8859-1 to UTF-8 before presenting (or storing it in Database) them. Following is my code: Configuration: Application server: Resin on Windows JDK (JVM): jre1.5.0_11 JVM default charset: UTF-8 Code: <% request.setCharacterEncoding("ISO-8859-1"); Sy   More>>

Hi,


I have a JSP with UTF-8 page encoding (I have
charset=UTF-8"> in HTML head).
This JSP receives form data from external website which are encoded in ISO-8859-1.
I have set request.setCharacterEncoding("ISO-8859-1"); in the beginning before getting parameter. I am trying to convert these ISO-8859-1 to UTF-8 before presenting (or storing it in Database) them.


Following is my code:


Configuration:


Application server: Resin on Windows


JDK (JVM): jre1.5.0_11


JVM default charset: UTF-8






Code:


<% request.setCharacterEncoding("ISO-8859-1");
System.out.println("Default charset:"+Charset.defaultCharset());
Enumeration params = request.getParameterNames();
while(params.hasMoreElements()) { String name = (String)params.nextElement(); String value = request.getParameter(name); String value1 = new String(value.getBytes("UTF-8")); System.out.println("Name:"+name+" value:"+value1); %> <%=name%> <%=name%>" value=" <%=value1%>" size="150"/>
<% } %>


Server Console Output:


Default charset:UTF-8


Name:subject value: Vincent ‘Sonny’ Pirozzi Jr., Merrimack






Actual encoded text in originating HTML:


Vincent ‘Sonny’ Pirozzi Jr., Merrimack





Do you see anything I am doing wrong? My intention is to convert ISO-8859-1 to UTF-8 characters on JVM with UTF-8 default charset?

   <<Less
About | Sitemap | Contact