• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unable to get Original data in Servlet from xmlhttprequest

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using below xmlhttprequest to sent data to server.


where mar="मे" which is marathi language.
and code written in servlet


It prints मà¥
By using below

System.out.println("String"+new String(marathi.getBytes("windows-1251"), "UTF-8"));
System.out.println("String"+new String(marathi.getBytes("ISO-8859-15"), "UTF-8"));

gets
String?��???
String�?�े
Please help me to sort out this issue. I already set UTF-8 format in eclipse.

Thanks in Advance

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where does it print that? Many consoles/terminals will not be able to handle anything beyond ISO-8859-1. Have you checked in the Java code whether the character is actually wrong?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

System.out.println("String"+new String(marathi.getBytes("windows-1251"), "UTF-8"));
System.out.println("String"+new String(marathi.getBytes("ISO-8859-15"), "UTF-8"));


This makes no sense. If you have bytes in Windows-1251 (or ISO-8859-15) you can't treat them as UTF-8. But this conversion back and forth accomplishes nothing even if implemented correctly.
 
pramod mhatre
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Actually I tried this directly in Java and printing it on eclipse console its worked. But as soon as I send data through xmlhttprequest to servlet its showing as above.

Thanks
 
author
Posts: 297
5
Android Firefox Browser Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're sending mar as a URL parameter. In this situation you have to percent encode any characters that aren't part of the ASCII character set as well as any of the special reserved characters (although the encoding itself is based off UTF-8 rather than ASCII). Since you're using POST rather than GET, you should be able to avoid having any URL parameters at all and just have everything as part of the post data which could then use the character encoding specified in the headers.
 
pramod mhatre
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Added parameter in post data and setting it encoded header worked.
Thank you so much Rob.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic