Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Tomcat - JSP/Servlet container
Struts - A MVC web framework
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
JSP - A mailing list about Java Server Pages specification and reference
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Subject: Servlet : Session invalidate
Oracle Connection Pooling in 3 2 2
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Subject: Running a Simple JMS Example
Tomcat and webapplication specific java library path
Mapping in workers2 properties
org apache jasper JasperException
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action
   MESSAGE
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
Value attribute of <html:checkbox
url string for connecting jboss to oracle
javax servlet ServletException: BeanUtils populate
5 0 18: Windows XP Pro vs Windows 2000
HTTP Status 404 The requested resource is not available
 
setCharacterEncoding for request/response objects

setCharacterEncoding for request/response objects

2004-09-28       - By Peter Claesson

 Back
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 (See http://ows-874.ora-code.com). 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 (See http://ows-874.ora-code.com)"); 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 (See http://ows-874.ora-code.com).

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(com.newatlanta.servletexec.Request@(protected))  :
windows-874 (See http://ows-874.ora-code.com)
[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 (See http://iso-8859.ora-code.com)-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 (See http://ows-874.ora-code.com)
[Wed Sep 22 08:15:53 PDT 2004] 9/22/04 8:15:53 AM AFT:
response.getCharacterEncoding = windows-874 (See http://ows-874.ora-code.com)

The only way I can get the request and response objects to use windows-874 (See http://ows-874.ora-code.com)
is by using a page directive <%@ page contentType = "text/html;
charset=windows-874 (See http://ows-874.ora-code.com)" %> 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 listserv@(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

©2008 junlu.com - Jax Systems, LLC, U.S.A.