• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to indentify Double byte or single byte from the request

 
saravanan kanda swamy
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
 
Christophe Verré
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 :

 
dema rogatkin
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!