This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

How to indentify Double byte or single byte from the request  RSS feed

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a scenario like this. The user will send the japaense data in the request parameter. He is sending the double byte characters and single byte chracters. Is there any method to find out the if it is a double byte or single byte character. from the HttpServletRequest object.

Because what is happening is once we got the data using the request.getParameter we are getting a string there all the characters are shown as single bytes only. But I need to separate single byte characters and double byte chracters.

Thanks in advance

Saravanan.K
 
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Characters in Java are two-bytes.
So the String you get with getParameter() should be ok.
Isn't it an encoding problem ?
 
saravanan kanda swamy
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

No encoding is not at all a problem. But when get that value from the string

String strReq = Request.getParameter("DATA");

I am doing this to find that value

byte b[]= strReq.getBytes()

System.out.println("The size is "+b.length);

It is giving the same length as the length of string .

Even though character in java are 2 bytes. How will you separate the japaense double byte and single byte from a string.

Thanks and Regards,
Saravanan.K
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Getting them one by one doesn't work ?

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I've understood your problem.
The data containing japanese will be converted into ISO_8859_1.
So you have to convert it back to the encoding you want.
For example, into ShiftJIS:
Like this :

 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
println will print Japanese as ??? at least it does for Russian unless I change encoding for System.out. I use
if (Character.UnicodeBlock.of(c).equals(Character.UnicodeBlock.KATAKANA ))
...
for the same task.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!