Take the tour ×

I am sending plain text to a servlet using jquery ajax POST. In my servlet i am setting the request character encoding like this :


and after that i am saving that text in database.

Now in another servlet i want to response the text stored in DB ... All the things are working fine.i can see the text on browser window when i call servlet without any problem..

but when i save that file and try to open it in notepad(windows) , i got some characters missing and displayed as a small rectangular box. however the text file looks fine in other editors like edit+ and notepad++

I tried this with no success..

response.setContentType("text/plain; charset=utf-8");

what is wrong in this ?

share|improve this question
If I understand correctly the characters are only broken when you open the file with notepad but with all other tools everything is okay. Then I would suspect notepad to be unable to cope with UTF-8, which would not surprise me. In Notepad++ you should be able to see the used encoding. I don't have the English version at hand but it should be the fifth menu from the left and called "Encoding". That should show you what encoding the file is stored it. –  Candlejack Jul 10 '12 at 12:07
add comment

2 Answers

up vote 1 down vote accepted

If it looks fine in other editors, then the text itself is fine. If it looks OK in the browser, then the response is probably fine too (but better check page info in the browser and see what the encoding is). Your problem is probably with notepad itself. Sometimes it requires BOM to detect Unicode properly. But BOM can break other apps that don't support it. You should also try Notepad on different versions of Windows. I have just tried opening an UTF-8 file in Windows 7, looks fine to me.

share|improve this answer
i can see the encoding in notepad++ its ANSI .where i want it to be UTF-8 –  JAVAGeek Jul 10 '12 at 12:10
@JAVAGeek, if it's really ANSI then Notepad shouldn't have any problems with reading it. It means that Notepad++ is wrong, and it's not ANSI. By UTF-8 Notepad++ means "UTF-8 with BOM", which isn't strictly correct, as UTF-8 without BOM is UTF-8 too. To be sure, look at your file using some hex viewer - if symbols outside of 7-bit ASCII are encoded as 2 or more bytes, then it's really UTF-8. –  Sergey Tachenov Jul 11 '12 at 10:44
add comment

If you use tomcat as an application server you might want to add this to its configuration: "-Dfile.encoding=UTF-8"

Also, take a look here: Setting the default Java character encoding?

share|improve this answer
add comment

Your Answer


