• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpServletResponse character encoding - best practice?

 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use the Netbeans IDE, and its servlet template uses this line:

response.setContentType("text/html;charset=UTF-8");

Is that best practise though for setting the response's character encoding? I was wondering if it would be better to either:
1. Use the same character encoding for the response as was detected for the request
or 2. Examine the "accept-charset" header of the request to detect and use the client's preferred character encoding for the response.

Does anyone know what the best practice would be?

Thanks,
James
 
Monika Joshi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi James, Here the MIME type of the following document is specified.Default for servlets is text/plain, but they usually explicitly specify text/html.For eg: if the document type were image, audio, video and application, the content type that dhd be set would be image/jpeg, audio/mp3, video/mp4, and application/msword respectively.

Regards,
Minakshi
 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Minakshi, but I was really asking about the character encoding rather than the MIME types. I.e., if the client sends you its data with ISO-8859-1 encoding or says it prefers that encoding, would it be considered best practice to return text content with the same encoding or just stick to UTF-8?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic