Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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 ]
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic