This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

xxxCharacterEncoding methods.....

 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am surprised that xxxCharacterEncoding() methods are available on ServletRequest and ONLY getCharacterEncoding() on ServletResponse.
I was expecting to find getCharacterEncoding() on the ServletRequest and setCharacterEncoding(...) on the ServletResponse......
Any insights please......
- satya
 
Guy Allard
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For response objects:
response.setContentType("text/html;charset=.....");
Regards, Guy
 
Gaja Venkat
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi:
>>I was expecting to find getCharacterEncoding() on the ServletRequest and setCharacterEncoding(...) on the ServletResponse......
It sounds quite logical to expect ServletRequest interface to have getCharacterEncoding() only and ServletResponse interface to have a similar method for setting charset, say setCharacterEncoding(String var).
As we know, ServletRequest has setCharacterEncoding(String env) method inaddtion to getCharacterEncoding(). The spec gives a good reason for including setCharacterEncoding(String env) in ServletRequest interface.
If the client (i.e browser) does not send a character encoding qualifier, it is upto the container to decide the character encoding and the container uses the default encoding (ISO-8859-I). Here, if the request data is encoded with a different encoding other than the default, breakage occurs. To avoid this, setCharacterEncoding method has been added so that the devloper can override the character encoding suppiled by the container by calling this method. And, this method should be called before any input is read from the request.
Now coming to ServletResponse, for getting the character encoding it has getCharacterEncoding() and for setting charset, it has the following two methods.
setContentType(String type) - here type is the MIME type
setLocale(Locale loc) - loc is the locale of the response
Hope this is clear,
Gaja Venkat
-------------------------------------------
Sun Certfied Programmer for Java 2 Platform
[ March 06, 2002: Message edited by: Gaja Venkat ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic