W3C home > Mailing lists > Public > www-international@w3.org > October to December 2002

RE: UTF-8 issue with JSP for tomcat server

From: Thierry Sourbier <ml@i18nGurus.com>
Date: Mon, 16 Dec 2002 21:43:03 +0100
To: "Mushtaq \(by way of Martin Duerst <duerst@w3.org>\)" <mushtaq@ssoftnet.com>, <www-international@w3.org>
Message-ID: <AMEFKKHPAGEPOAOBAOBMKECFCLAA.ml@i18nGurus.com>

Dear Mushtaq,

There is likely a bug in your code. I'm attaching a sample JSP you can play
with to send/retreive Arabic text (I just retested Tomcat 4.0.6 with Arabic
data and it works without problems for me).

Cheers,
Thierry

+---------------------------------------->
www.i18nGurus.com - The Open Internationalization Resources Directory.


=== Sample JSP starts here =======================
<%@ page
    language="java"
    import="java.util.Enumeration"
    pageEncoding="utf-8"
    contentType="text/html;charset=utf-8"
%>
<html>

<body bgcolor="white">

Here you test how forms behave and/or misbehave:<br>
<b>Form get</b><form method=get>
<input name='form:get'size=50 type=text>
<input type=submit value=submit>
</form>

<b>Form post</b>
<form method=post>
<input name='form:post' size=50 type=text>
<input type=submit value=submit>
</form>
<hr>
<%
	request.setCharacterEncoding("UTF-8");
	Enumeration e = request.getParameterNames();
	if(e != null && e.hasMoreElements()) {
%>
<b>Request parameters</b><br>
<br>
The parameters are read after calling request.setCharacterEncoding("UTF-8");
<bR>
<TABLE>
<TR valign=top>
	<TH align=left>Parameter:</TH>
	<TH align=left>Value:</TH>
</TR>
<%
		while(e.hasMoreElements()) {
			String k = (String) e.nextElement();
			String val = request.getParameter(k);
%>
<TR valign=top>
	<TD><%= k %></TD>
	<TD><%= val %></TD>
</TR>
<%
		}
%>
</TABLE>
<%
	}
%>
</body></html>

=== End Sample JSP =======================
Received on Monday, 16 December 2002 15:44:32 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 2 June 2009 19:16:59 GMT