M
Matthias Krueger
I am currently trying to post and read UTF-8 encoded characters
on my JSP pages in an Tomcat 4.1 environment. Whenever I post
a German umlaut or a Chinese or Arabian character into my form,
the result displayed on my web page is complete garbage. I tried
the usual "tricks" like
- <%@ page contentType="text/html;charset=utf-8" %>
- request.setCharacterEncoding("UTF-8");
- response.setContentType("text/html; charset=utf-8");
with no success. I thought all the problems with different character
encodings would be gone with UTF-8 but no I am stuck here for more
than 1 day.
Here's my current code (just a slightly modified version of the
sample JSP found at
http://lists.w3.org/Archives/Public/www-international/2002OctDec/0148.html
PS: From my system.out logs:
Current request encoded with: UTF-8
Current response encoded with: UTF-8
My IE6 on Win2000 is also switched to UTF-8
What is going on here ???
:/
Thank you in advance for any suggestions,
Matthias
-------[snip]--------------------------------------------[snap]------
<%@ page
language="java"
import="java.util.Enumeration"
pageEncoding="utf-8"
contentType="text/html;charset=utf-8"
%><%
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=utf-8");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body bgcolor="white">
<b>Form post</b>
<form method="post" accept-charset="UTF-8">
<input name="textfeldmb" type="text">
<textarea name="textareamb"></textarea>
<input type="submit" value="submit">
</form>
<hr>
<%
System.out.println("Current request encoded with: " +
request.getCharacterEncoding());
System.out.println("Current response encoded with: " +
response.getCharacterEncoding());
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);
System.out.println("request parameter " + k + ": " + val);
%>
<TR valign=top>
<TD><%= k %></TD>
<TD><%= val %></TD>
</TR>
<%
}
%>
</TABLE>
<%
}
%>
</body></html>
on my JSP pages in an Tomcat 4.1 environment. Whenever I post
a German umlaut or a Chinese or Arabian character into my form,
the result displayed on my web page is complete garbage. I tried
the usual "tricks" like
- <%@ page contentType="text/html;charset=utf-8" %>
- request.setCharacterEncoding("UTF-8");
- response.setContentType("text/html; charset=utf-8");
with no success. I thought all the problems with different character
encodings would be gone with UTF-8 but no I am stuck here for more
than 1 day.
Here's my current code (just a slightly modified version of the
sample JSP found at
http://lists.w3.org/Archives/Public/www-international/2002OctDec/0148.html
PS: From my system.out logs:
Current request encoded with: UTF-8
Current response encoded with: UTF-8
My IE6 on Win2000 is also switched to UTF-8
What is going on here ???
:/
Thank you in advance for any suggestions,
Matthias
-------[snip]--------------------------------------------[snap]------
<%@ page
language="java"
import="java.util.Enumeration"
pageEncoding="utf-8"
contentType="text/html;charset=utf-8"
%><%
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=utf-8");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body bgcolor="white">
<b>Form post</b>
<form method="post" accept-charset="UTF-8">
<input name="textfeldmb" type="text">
<textarea name="textareamb"></textarea>
<input type="submit" value="submit">
</form>
<hr>
<%
System.out.println("Current request encoded with: " +
request.getCharacterEncoding());
System.out.println("Current response encoded with: " +
response.getCharacterEncoding());
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);
System.out.println("request parameter " + k + ": " + val);
%>
<TR valign=top>
<TD><%= k %></TD>
<TD><%= val %></TD>
</TR>
<%
}
%>
</TABLE>
<%
}
%>
</body></html>