File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes xxxCharacterEncoding methods..... Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Web Component Certification (SCWCD/OCPJWCD)
Reply Bookmark "xxxCharacterEncoding methods....." Watch "xxxCharacterEncoding methods....." New topic
Author

xxxCharacterEncoding methods.....

Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
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


Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Guy Allard
Ranch Hand

Joined: Nov 24, 2000
Posts: 776
For response objects:
response.setContentType("text/html;charset=.....");
Regards, Guy
Gaja Venkat
Ranch Hand

Joined: Aug 10, 2001
Posts: 50
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 ]
 
 
subject: xxxCharacterEncoding methods.....
 
Threads others viewed
long time no doubts?
Do I need to memorize?
what methods to learn
Internationalization
Last days of preparation
MyEclipse, The Clear Choice