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
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
JSP - A mailing list about Java Server Pages specification and reference
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
Oracle Connection Pooling in 3 2 2
Servlet : Session invalidate
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Tomcat and webapplication specific java library path
Running a Simple JMS Example
Mapping in workers2 properties
org apache jasper JasperException
Cannot find message resources under key org apache struts action
   MESSAGE
problem with html:text bean throwing exception
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
url string for connecting jboss to oracle
Value attribute of <html:checkbox
javax servlet ServletException: BeanUtils populate
HTTP Status 404 The requested resource is not available
5 0 18: Windows XP Pro vs Windows 2000
 
encoding problems: UTF-8 vs ISO-8859-1

encoding problems: UTF-8 vs ISO-8859-1

2007-02-05       - By Pierre Thibaudeau

 Back
Reply:     1     2     3  

I seem to have a problem of consistency between UTF-8 (See http://UTF-8.ora-code.com) and ISO-8859 (See http://ISO-8859.ora-code.com)-1 when it
comes to accepting Strings in forms.  Here's how it goes:

* My application is intended to be entirely UTF-8 (See http://UTF-8.ora-code.com) encoded:  the database,
the JSP files, etc.
Only exceptions are the localized ApplicationResources_??.properties files,
which are encoded as ISO-8859 (See http://ISO-8859.ora-code.com)-1, as per
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html
That part works very well.

* I use Tiles, and I include the following line at the beginning of every
tile and every layout page:
<%@ page contentType="text/html;charset=UTF-8 (See http://UTF-8.ora-code.com)" language="java"
pageEncoding="UTF-8 (See http://UTF-8.ora-code.com)"%>

* Also, in the tile that generates the <HEAD> of the HTML files, I include
the following:
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8 (See http://utf-8.ora-code.com)" />

So far, everything works fine and all the localized messages display
properly with all the desired accents and diacritic signs.

Everything... except in the case of a text form:
<html:form action="/search" acceptCharset="UTF-8 (See http://UTF-8.ora-code.com)">
<html:text property="query"/><br/>
<html:submit titleKey="search.search" >
 <bean:message key="search.executeSearch" />
</html:submit>
</html:form>

The ActionForm is defined dynamically in the struts-config.xml file:
<form-bean name="NameSearchForm" type="
org.apache.struts.action.DynaActionForm Source code of org.apache.struts.action.DynaActionForm">
   <form-property name="query" type="java.lang.String Source code of java.lang.String" />
</form-bean>

And the Action:
   <action
     path="/search"
     name="NameSearchForm"
     scope="request"
     type="com.mystuff.NameSearchAction"
     validate="false">
     <forward name="results" path=".results" redirect="false" />
     <forward name="noresult" path=".noresult" redirect="false" />
   </action>

On input of a query string, the NameSearchAction retrieves this string:
       String queryStr = (String) PropertyUtils.getSimpleProperty(form,
"query");

But that's where I get into trouble.  Suppose, in the text form, I type the
query "C?sar" (the second letter being an e-acute).  If on the following
"noresult" JSP page, I re-display the content of the query, I then get:
"C?(c)sar".  (The second and third characters are now respectively an
uppercase-A-tilde and a copyright-sign.)  That, to me, looks like a conflict
between ISO-8859 (See http://ISO-8859.ora-code.com)-1 and UTF-8 (See http://UTF-8.ora-code.com).  Where's the catch?


[Using Struts 1.3.5, Java 5, Tomcat 6.0;  this experiment is run within
Eclipse/MyEclipse 5.1.0.]

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