I recently sat down to read the JSP spec (1.1) and discovered that it only
allows for one
character set per page.  This means that the spec designers intend for page
authors
to write a version of their page for each localization of their web
application.  This makes
it extremely difficult to write one page, use resource bundles to store
text, and dynamically
negotiate the character set with the client.  How do you do the following
servlet code
in JSP?

     Locale clientLoc = determineLocaleFromRequest(request);
     String charset = determineCharsetFromRequest(request);

     response.setContentType("text/html; charset=" + charset);

     PrintWriter out = response.getWriter(); // writer uses the previous
specific character set

     ResourceBundle res = ResourceBundle.getBundle
("MyAppStrings",clientLoc);

     ...
     out.println(res.getString("foo")); // assuming that the resource data
is stored in Unicode
     ...

As far as I can tell, the only way to have a single JSP is to mandate the
use of UTF8.
This is a pretty ridiculous requirement.  Are people just not using JSP to
write I18N
compliant applications?

Ok, this leads to my next point: why isn't all of this locale detection and
character set
stuff built into the Servlet API?  Why can't you do:

     // Set the character set encoding for converting parameters
     request.setCharacterEncoding(charset);

     String param1 = request.getParameter("Param1");
     ...
     String[] params = request.getParameterValues("Params");

instead of the more cumbersome:

     String param1 = new String(request.getParameter
("Param1").getBytes(request.getCharacterEncoding()),charset);
     ...
     String[] params = request.getParameterValues("Params");
     for( int i = 0; i < params.length; ++i ) {
          params[i] = new
String(params[i].getBytes(request.getCharacterEncoding()),charset);
     }

I know I can write a wrapper that does this for me, but it would be much
nicer if the API had this functionality
built in for situations where a wrapper isn't convenient or even possible
(such as existing code).

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to