I am struggling with a localization issue where I want to set the encoding
of both the request and response objects at run-time. I have an applicatoin
consisting of 17 JSP pages that now must support Thai. I'm unable to use
UTF8 due to the fact that I need to pass the data over to a windows server,
which only support 8-bit characters. I'm using ServletExec 5.0 on Windows.

The encoding I'm trying to use is windows-874. I've set both the request
and response objects using setCharacterEncoding, but the page returned to
the browser is still ISO8859-1.

I have also tried calling response.setContentType("text/html;
charset=windows-874"); with the same result.
Carefully reading the the API descriptions for getCharacterEncoding,
getContentType, setCharacterEncoding, and setContentType
it appears that both setCharacterEncoding and setContentType must be
called. I've tried that with the same result. The page is
always returned to the browser with ISO8859-1 encoding.

I even read the encoding (in my filter) before I set it and after it is
set.

Here is a copy of the doFilter method. The "encode" variable is set in init
method to value windows-874.

 public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws ServletException, IOException
 {
                Debug.println("HtmlcEncodingFilter.doFilter(" + request
+ ")  : " + encode);
                HttpServletRequest req  = (HttpServletRequest) request;
                HttpServletResponse res = (HttpServletResponse) response;
                Debug.println("BEF: request.getCharacterEncoding = " +
req.getCharacterEncoding());
                Debug.println("BEF: response.getContentType = " +
res.getContentType());
                Debug.println("BEF: response.getCharacterEncoding = " +
res.getCharacterEncoding());
                req.setCharacterEncoding(encode);
                res.setCharacterEncoding(encode);
                res.setContentType("text/html;charset=" + encode);
                Debug.println("AFT: request.getCharacterEncoding = " +
req.getCharacterEncoding());
                Debug.println("AFT: response.getContentType = " +
res.getContentType());
                Debug.println("AFT: response.getCharacterEncoding = " +
res.getCharacterEncoding());
                chain.doFilter(request, response);  // chain filter, if
needed
  return;
 }

This is what the SE log shows.

[Wed Sep 22 08:15:53 PDT 2004] 9/22/04 8:15:53 AM
HtmlcEncodingFilter.doFilter([EMAIL PROTECTED])  :
windows-874
[Wed Sep 22 08:15:53 PDT 2004] 9/22/04 8:15:53 AM BEF:
request.getCharacterEncoding = null
[Wed Sep 22 08:15:53 PDT 2004] 9/22/04 8:15:53 AM BEF:
response.getContentType = null
[Wed Sep 22 08:15:53 PDT 2004] 9/22/04 8:15:53 AM BEF:
response.getCharacterEncoding = iso-8859-1
[Wed Sep 22 08:15:53 PDT 2004] 9/22/04 8:15:53 AM AFT:
request.getCharacterEncoding = null
[Wed Sep 22 08:15:53 PDT 2004] 9/22/04 8:15:53 AM AFT:
response.getContentType = text/html;charset=windows-874
[Wed Sep 22 08:15:53 PDT 2004] 9/22/04 8:15:53 AM AFT:
response.getCharacterEncoding = windows-874

The only way I can get the request and response objects to use windows-874
is by using a page directive <%@ page contentType = "text/html;
charset=windows-874" %> in each JSP page. As we do not want to maintain
hardcoded values, I'm desperate of getting this to work.

Am I doing something wrong? or is there a bug?

I'm grateful for any help or pointers.

/Peter

___________________________________________________________________________
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