It may be ignoring the character encoding specified in the content type because you are setting it to something other than text/html
.
Try setting the character encoding using setCharacterEncoding()
instead (make sure to call it before calling getWriter()
).
response.setContentType("text/vcard");
response.setCharacterEncoding("UTF-8");
response.setStatus(HttpServletResponse.SC_OK);
PrintWriter writer = response.getWriter();
Also, make sure your text editor is reading the file correctly. During my testing, I found that Eclipse would not display UTF-8 characters correctly, because it was configured to load the file under a different character set. Try viewing the file contents from the terminal:
cat the-vcard-file.vcf
EDIT: One more thing: Do not close the VCardWriter
object. This will close the servlet's PrintWriter
object, which you must never close!!