• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

HttpServletResponse character encoding - best practice?

 
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
 
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?
 
    Bookmark Topic Watch Topic
  • New Topic