You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Karanjkar, Sanjay V (IT)" <Sa...@morganstanley.com> on 2005/06/02 15:30:46 UTC
Tomcat 5.0.30 - UTF-8 encoding not working
Hi msjava,
I'm trying to migrate our webapp from ServletExec4.1.1/JDK1.3.1 to Tomcat5.0.30/JDK1.4.2.
On ServletExec, our app was showing/saving UTF-8 strings correctly. However, after migration to Tomcat, the pages are not showing UTF-8 encoded content correctly.
All our JSP pages contain the following:
---------------------------------------
<%@ page import="java.util.*, java.lang.*" contentType="text/html; charset=UTF-8" %> ...
...
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
The web.xml file contains:
-------------------------
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
....
....
A filter servlet for all JSPs:
-----------------------------
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
{
try
{
if (null != encoding)
{
request.setCharacterEncoding(encoding);
}
filterChain.doFilter(request, response); ....
....
....
Do I need to do something else for Tomcat? In particular, do I need to do the stuff mentioned here: http://wiki.apache.org/jakarta-tomcat/Tomcat/UTF-8
Thanks in advance
Sanjay
--------------------------------------------------------
NOTICE: If received in error, please destroy and notify sender. Sender does not waive confidentiality or privilege, and use is prohibited.
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Tomcat 5.0.30 - UTF-8 encoding not working
Posted by Mark Thomas <ma...@apache.org>.
Karanjkar, Sanjay V (IT) wrote:
> Hi msjava,
>
> I'm trying to migrate our webapp from ServletExec4.1.1/JDK1.3.1 to Tomcat5.0.30/JDK1.4.2.
> On ServletExec, our app was showing/saving UTF-8 strings correctly. However, after migration to Tomcat, the pages are not showing UTF-8 encoded content correctly.
If your are POSTing your data, request.setCharacterEncoding("UTF-8")
should do the trick but you MUST call this before any parameters are read.
If you are encoding your data in the URI, you will need to set the
URIEncoding attribute on the coyote connector to "UTF-8" to ensure that
the URI is decoded correctly.
> Do I need to do something else for Tomcat? In particular, do I need to do the stuff mentioned here: http://wiki.apache.org/jakarta-tomcat/Tomcat/UTF-8
1. Yes
2 & 3 - No . These might work under some circumstances but 2. is trying
to change a read-only property and 3. is hacking around the data not
being handled correctly in the first place.
When I am testing this, I use the following JSP to make sure Tomcat is
correctly configured. A clean Tomcat install should only require
URIEncoding="UTF-8" to be added to the connector in server.xml for these
to work for any UTF-8 data. You should test it with both method="post"
and method="get"
<%@ page contentType="text/html; charset=UTF-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>UTF-8 test page</title>
</head>
<body>
<p>UTF-8 data posted to this form was:
<%
request.setCharacterEncoding("UTF-8");
out.print(request.getParameter("mydata"));
%>
</p>
<form method="post" action="index.jsp"
enctype="application/x-www-form-urlencoded">
<input type="text" name="mydata">
<input type="submit" value="Submit" />
<input type="reset" value="Reset" />
</form>
</body>
</html>
If this works, then the chances are your app isn't quite right. If you
have a test case that doesn't work (try and make it as simple as
possible) post it to the list and I'll take a look.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org