xml-xsp-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fo...@neonics.com
Subject Re: Problem with Character Encoding in Cocoon 2 / Postgres
Date Wed, 11 Dec 2002 13:10:29 GMT
On Wed, 11 Dec 2002, Yves Vindevogel wrote:


I use Unicode with UTF-8 encoding everywhere which works fine, but you
could also default to Latin1.

First, your postgresql database server needs to be compiled with
--enable-multibyte=....... (I chose UNICODE but see the documentation
for other available character encodings, you should choose Latin1 or
something similar).

Next, create your database:

 createdb -E=Latin1 .........

This makes sure the characters are stored in Latin1, not the default
encoding used in postgres.

Next, you need your generated HTML page to specify the content-encoding
using a header in the http request
(Content-type: text/html; encoding=Latin1)

I don't know how to do this in Cocoon, maybe you can configure the
serializer to set the content type?

and also in the <head> tags of the page: 

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

This makes sure the browser uses this encoding when submitting form data.

Next, you need to make sure the HttpServletRequest will process the 
submitted data as Latin1. You should call the following method
BEFORE extracting the request data:

  request.getCharacterEncoding("Latin1");

(note: if you use struts or another mechanism that retrieves the 
request parameters for you, you can use the SetCharacterEncoding filter
which comes with tomcat).

Now you should be all set.

Although I'd recommend using UTF-8 as encoding since it supports the
complete UNICODE (ucs2) character set, so your app will also be useful
in Japan :)


Hope this helps. Took me a while to get things working just fine,
especially since you need to make sure all your components agree on the
character encoding (database, servlet output, servlet input, browser
display, browser submitted-data).

Oh, it might be useful to run tomcat with the correct locale/language
settings (if you use unix/linux):

export LANG=fr_FR@euro  (or some other encoding; I use en_US.UTF-8,
which enables the use of UTF-8 in filenames too :)


Greetings,

	Kenney Westerhof



> This was also posted on cocoon-users.  But I don't know if this is Cocoon 
> related or XSP related.
> 
> ----------    ----------
> 
> Subject: Problem with Character Encoding in Cocoon 2 / Postgres
> Date: Wed, 11 Dec 2002 10:32:26 +0100
> From: Yves Vindevogel <yves.vindevogel@implements.be>
> To: cocoon-users@xml.apache.org
> 
> Hi,
> 
> I'm using Cocoon 2 and Postgres 7 on Slackware 8, JDK 1.4.
> My database and pages contain French characters (like é,à,ç, ...)
> I use XSP to get the data from PG.
> 
> I can show all the data correctly when I set the encoding to ISO-8859-1.
> I wrote some plsql procedures to store data.  I call them from my XSP pages.
> This is where it goes wrong: the French characters are stored in an
>  unreadable manner.  (Storing is the only thing where it goes wrong)
> 
> Calling the function from the command line with the French characters works
> fine.  It's only when I post the page and call the function that it goes
> wrong.
> 
> Any ideas ??
> 
> 
> 
> 
> Here's some of my code:
> 
> 1) Sample XSP where it goes wrong
> <?xml version="1.0" encoding="ISO-8859-1"?>
> 
>     <xsp:page language="java"
>     			xmlns:xsp="http://apache.org/xsp"
> 			xmlns:esql="http://apache.org/cocoon/SQL/v2"
> 			xmlns:xsp-request="http://apache.org/xsp/request/2.0"
> 			xmlns:xsp-session="http://apache.org/xsp/session/2.0"
> 			create-session="true">
> 
>         <html>
> 		<head>
>         		<link rel="stylesheet" type="text/css"
> href="./../css/pierrefabre.css"/>
>         	</head>
> 
>                 <body>
>                 	<div style="position:absolute; left: 5px; top: 5px">
>                         	<img src="./../images/product.png"/>
>                         </div>
> 
>                         <div style="position:absolute; left: 60px; top: 5px">
>                         	<h1>Nouveau type de cancer</h1>
>                         </div>
> 
> 
>                         <div style="position:relative; top: 40px">
> 
> 
>             <esql:connection>
>                 <esql:pool>pierrefabre</esql:pool>
> 
>                 <esql:execute-query>
> 			<esql:query>
> 				select fnCancerTypeInsert ('<xsp-request:get-parameter
> name="description"/>')
> 			</esql:query>
> 
>                     	<esql:results>
> 				<esql:row-results>
> 					<xsp:logic>
> 						if (<esql:get-string column="fnCancerTypeInsert"/>.equals("1"))
> 						{
> 							<p class="error">Ce type de cancer existe déja.  Les modifications ne
> sont pas enrégistrées.</p>
> 						} ;
>                                                 if (<esql:get-string
> column="fnCancerTypeInsert"/>.equals("0"))
>                                                 {
> 							<p class="message">Les modifications sont enrégistrées.</p>
>                                                 };
> 					</xsp:logic>
> 
>                                         <input type="submit" value="Rétour"
> onclick="window.location = './cancertypes.list.html';" class="button"/>
> 				</esql:row-results>
> 		    	</esql:results>
> 
>                 </esql:execute-query>
>             </esql:connection>
> 			</div>
>             	</body>
>         </html>
>     </xsp:page>
> 
> 2) Cocoon.xconf setting for the database
> <datasources>
>     <jdbc name="pierrefabre">
>       <pool-controller max="10" min="5"/>
> 
> <dburl>jdbc:postgresql://10.32.1.3:5432/pierrefabre?charSet=LATIN1</dburl>
>       <user>postgres</user>
>       <password/>
>     </jdbc>
> 
> 
> 3) The pgplsql function called in that page
> create function fnCancerTypeInsert (varchar(50)) returns integer as
> '
> 	declare
>         	p_description alias for $1 ;
> 
>   		v_count integer ;
>         begin
>         	select into v_count count(*) from tblCancerTypes
>                 	where upper(description) = upper(p_description) ;
> 
>          	if v_count > 0 then
>                 	return 1 ;
>           	end if ;
> 
>                 insert into tblCancerTypes
>                 	values (p_description) ;
> 
>            	return 0 ;
>         end ;
> ' language 'plpgsql' ;
> 
> 
> 
> 
> 
> 
> 
> --
> Kind regards,
> Yves Vindevogel
> 
> Implements
> Kortrijkstraat 2 bus 1  --  9700 Oudenaarde  --  Belgium
> Phone/Fax: +32 (55) 45.74.73  --  Mobile: +32 (478) 80.82.91
> Mail: yves.vindevogel@implements.be  --  www.implements.be
> 
> Quote: The winner never says participating is more important than winning.
> 
> 

--
Kenney Westerhof
http://www.neonics.com
GPG public key: http://www.gods.nl/~forge/forge.key


Mime
View raw message