0

I have text box and a button. I am entering Japanese characters like こんにちは in text box.

When I click on button email is sent with the text in text box.

But when email receive it displays some junk character instead Japanese characters.

Can anybody please tell me why this is happening?

Thanks in advance.

7
  • Do you know the encodings being used? Commented Jun 3, 2013 at 15:14
  • Show the code you use to build the message body Commented Jun 3, 2013 at 15:16
  • String str= myEntity.getTextBoxValue();StringBuilder strb = new StringBuilder();strb.append(str);return strb.toString(); Commented Jun 3, 2013 at 15:23
  • @user2448398 You can simplify that to return myEntity.getTextBoxValue();. Commented Jun 3, 2013 at 15:36
  • but before appending to StringBuilder , if i do System.out.println(str); that time only it shows junk character. also I used charset as content="text/html;charset=UTF-8" Commented Jun 3, 2013 at 16:13

2 Answers 2

1

You should make sure that you are using a character set that supports Japanese characters, like Unicode.

For instance, when creating a String object there is an overloaded constructor where you can specify character encoding:

byte[] utf8Characters = { /* UTF-8 encoded characters */ };
String s = new String(characters, "UTF-8"); // Decode bytes using UTF-8.

Also when converting Strings to bytes (ie when streaming data) you can use:

byte[] utf8EncodedBytes = s.getBytes("UTF-8"); // Encode to UTF-8.

If you do not specify character encoding it will default to some charset which might not support the characters you need.

Java Doc says: "The default charset is determined during virtual-machine startup and typically depends upon the locale and charset being used by the underlying operating system."

Sign up to request clarification or add additional context in comments.

6 Comments

Hello snipes83,Thanks for your reply.I tried things as you suggested but still I am seeing Junk charcters. I tried as , byte[] b= myEntity.getTextBoxValue().getBytes("UTF-8"); String value = new String(b, "UTF-8"); System.out.println(value); // it prints π??π??π?¬π?? characters
@user2448398 If your program gives you junk when printing the String given by myEntity.getTextBoxValue(), then the problem is probably in how myEntity handles the charset encoding. What does myEntity represent?
it just simply holds value entered in the text box. public class MyEntity {private String textBoxValue; //getter,setter of this}.
@user2448398 and how do you set the string value of MyEntity? From a HTML form?
yes I verified ,my javascript is also already set using UTF-8 ,<script src="js/data.js" type="text/javascript" charset="UTF-8"/>.Any other suggesions ?
|
0

im not really sure if you are using java servlets but if you do, you can try this

request.setCharacterEncoding("UTF-8");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.