• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

xxxCharacterEncoding methods.....

 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For response objects:
response.setContentType("text/html;charset=.....");
Regards, Guy
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
No one can make you feel inferior without your consent - Eleanor Roosevelt. tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic