You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Yigal Lazarev <yl...@gmail.com> on 2007/11/08 01:14:01 UTC
Tomcat 6.0.14 and UTF-8 POST form problem
Hi,
I'm deploying a JSF WAR onto Tomcat 6.0.14 under Windows 2003 with JVM
version 1.6.0_03-b05, and using MySQL db.
When I submit a form using POST method, and in the server side take the
fields and send them as an email using JavaMail- i lose the UTF-8 encoded
characters sent in the form.
I suspect it's something with the Tomcat configuration because it does not
happen when I deploy to Sun Application Server 8.2
And another thing, UTF-8 characters hardcoded in the sending email method
are sent just fine.
After a week of web search and reading documentation, what I tried so far:
* * Converting from ISO to UTF: *
String subj = "קורות חיים של "+new
String(((String)nameTextField.getValue()).getBytes("ISO-8859-1"), "UTF-8");
message.setSubject(subj, "utf-8");
Also doesn't work with ISO-8859-8 which is for hebrew, what I'm trying to
type..
*
* Inserting URIEncoding="UTF-8" in the HTTP connector in server.xml. *
*
* Making a filter that will change the request encoding to utf-8:
*
The filter class:
public class ReqEncodingFilter implements Filter {
public void destroy() { }
/** Preform the filtering. */
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding("UTF-8");
chain.doFilter(request, response);
}
public void init(FilterConfig config) throws ServletException { }
}
Also tried with the example encoding filter that comes with Tomcat. The
web.xml part:
<filter>
<filter-name>Set Character Encoding Filter</filter-name>
<filter-class>yarivmt.ReqEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UploadFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>Set Character Encoding Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Also tried with <servlet-name>Faces Servlet</servlet-name> instead of the
url-pattern tag.
* * Making a locale-encoding-mapping-list in web.xml: *
<locale-encoding-mapping-list>
<locale-encoding-mapping>
<locale>en</locale>
<encoding>UTF-8</encoding>
</locale-encoding-mapping>
<locale-encoding-mapping>
<locale>he</locale>
<encoding>UTF-8</encoding>
</locale-encoding-mapping>
<locale-encoding-mapping>
<locale>ru</locale>
<encoding>UTF-8</encoding>
</locale-encoding-mapping>
<locale-encoding-mapping>
<locale>iw</locale>
<encoding>UTF-8</encoding>
</locale-encoding-mapping>
<locale-encoding-mapping>
<locale>ru_RU</locale>
<encoding>UTF-8</encoding>
</locale-encoding-mapping>
</locale-encoding-mapping-list>
Any suggestions where to look highly appreciated!
Re: Tomcat 6.0.14 and UTF-8 POST form problem
Posted by Michael <sg...@gmx.net>.
Yigal Lazarev wrote:
> Well Michael you've just solved the problem!
> Thank you very much ! :)
You are welcome!
Try to avoid top posting in future:
http://en.wikipedia.org/wiki/Posting_style
Which barely impossible to read
Cheers to israel,
Mike
--
<NO> OOXML - Say NO To Microsoft Office broken standard
http://www.noooxml.org
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat 6.0.14 and UTF-8 POST form problem
Posted by Yigal Lazarev <yl...@gmail.com>.
Well Michael you've just solved the problem!
Thank you very much ! :)
On Nov 8, 2007 12:46 PM, Michael <sg...@gmx.net> wrote:
> Michael wrote:
> > Yigal Lazarev wrote:
> >> Shalom Michael,
> >> Thanks for your reply, but as you can see in my first post, this was
> the
> >> second thing I tried..
> >> Inserting URIEncoding="UTF-8" to the HTTP and the AJP/1.3 connectors in
> >> server.xml didn't help.
> >> More suggestions?
> >
> > did you tell the JVM to use UTF-8 as file encoding?
> >
> > -Dfile.enconding=UTF-8
> >
> -Dfile.encoding=UTF-8
>
> --
> <NO> OOXML - Say NO To Microsoft Office broken standard
> http://www.noooxml.org
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
Re: Tomcat 6.0.14 and UTF-8 POST form problem
Posted by Michael <sg...@gmx.net>.
Michael wrote:
> Yigal Lazarev wrote:
>> Shalom Michael,
>> Thanks for your reply, but as you can see in my first post, this was the
>> second thing I tried..
>> Inserting URIEncoding="UTF-8" to the HTTP and the AJP/1.3 connectors in
>> server.xml didn't help.
>> More suggestions?
>
> did you tell the JVM to use UTF-8 as file encoding?
>
> -Dfile.enconding=UTF-8
>
-Dfile.encoding=UTF-8
--
<NO> OOXML - Say NO To Microsoft Office broken standard
http://www.noooxml.org
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat 6.0.14 and UTF-8 POST form problem
Posted by Michael <sg...@gmx.net>.
Yigal Lazarev wrote:
> Shalom Michael,
> Thanks for your reply, but as you can see in my first post, this was the
> second thing I tried..
> Inserting URIEncoding="UTF-8" to the HTTP and the AJP/1.3 connectors in
> server.xml didn't help.
> More suggestions?
did you tell the JVM to use UTF-8 as file encoding?
-Dfile.enconding=UTF-8
--
<NO> OOXML - Say NO To Microsoft Office broken standard
http://www.noooxml.org
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat 6.0.14 and UTF-8 POST form problem
Posted by Yigal Lazarev <yl...@gmail.com>.
Shalom Michael,
Thanks for your reply, but as you can see in my first post, this was the
second thing I tried..
Inserting URIEncoding="UTF-8" to the HTTP and the AJP/1.3 connectors in
server.xml didn't help.
More suggestions?
On Nov 8, 2007 11:28 AM, Michael <sg...@gmx.net> wrote:
> Yigal Lazarev wrote:
> > Hi,
> >
> > I'm deploying a JSF WAR onto Tomcat 6.0.14 under Windows 2003 with JVM
> > version 1.6.0_03-b05, and using MySQL db.
> > When I submit a form using POST method, and in the server side take the
> > fields and send them as an email using JavaMail- i lose the UTF-8
> encoded
> > characters sent in the form.
> >
> > I suspect it's something with the Tomcat configuration because it does
> not
> > happen when I deploy to Sun Application Server 8.2
> > And another thing, UTF-8 characters hardcoded in the sending email
> method
> > are sent just fine.
>
> Shalom Yigal,
>
> all your efforts are useless. Just do the following thing and you'll be
> happy:
>
> open up the server.xml
>
> search for the Connector node which works for HTTP and add the attribute
> URIEncoding="UTF-8"
> restart tomcat and go on using:
>
> String string = request.getParamter("name");
>
> that's it. Works perfectly here.
>
> Some reference for you:
>
> http://confluence.atlassian.com/display/DOC/Configuring+Tomcat's+URI+encoding<http://confluence.atlassian.com/display/DOC/Configuring+Tomcat%27s+URI+encoding>
>
> Lehitraot,
>
> Michael
> --
> <NO> OOXML - Say NO To Microsoft Office broken standard
> http://www.noooxml.org
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
Re: Tomcat 6.0.14 and UTF-8 POST form problem
Posted by Michael <sg...@gmx.net>.
Yigal Lazarev wrote:
> Hi,
>
> I'm deploying a JSF WAR onto Tomcat 6.0.14 under Windows 2003 with JVM
> version 1.6.0_03-b05, and using MySQL db.
> When I submit a form using POST method, and in the server side take the
> fields and send them as an email using JavaMail- i lose the UTF-8 encoded
> characters sent in the form.
>
> I suspect it's something with the Tomcat configuration because it does not
> happen when I deploy to Sun Application Server 8.2
> And another thing, UTF-8 characters hardcoded in the sending email method
> are sent just fine.
Shalom Yigal,
all your efforts are useless. Just do the following thing and you'll be
happy:
open up the server.xml
search for the Connector node which works for HTTP and add the attribute
URIEncoding="UTF-8"
restart tomcat and go on using:
String string = request.getParamter("name");
that's it. Works perfectly here.
Some reference for you:
http://confluence.atlassian.com/display/DOC/Configuring+Tomcat's+URI+encoding
Lehitraot,
Michael
--
<NO> OOXML - Say NO To Microsoft Office broken standard
http://www.noooxml.org
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat 6.0.14 and UTF-8 POST form problem
Posted by Yigal Lazarev <yl...@gmail.com>.
Thanks for the reply Chuck,
I read in the documentation that the default encoding in Tomcat for incoming
requests like from a form submission is Latin-1 (ISO-8859-1).
So the text in nameTextField (which is of type TextField) is UTF-8 text that
was 'treated' like Latin-1.
What I did is as suggested here:
http://www.jguru.com/faq/view.jsp?EID=1030399
to take the value (getValue() which returns an Object) and cast into String,
then take the bytes as Latin-1 and
construct a new String to return it to UTF-8.
Please correct me if I'm wrong.
I've changed the code a bit and it looks like this:
String nameText = (String)nameTextField.getText();
String convText = new String(ntft.getBytes("ISO-8859-1"), "UTF-8");
String subj = "קורות חיים של "+convText;
message.setSubject(subj, "utf-8");
getText() returns an Object so it has to be casted to String.
Still doesn't work.
Any suggestions are welcome..
On Nov 8, 2007 6:25 AM, Caldarale, Charles R < Chuck.Caldarale@unisys.com>
wrote:
> > From: Yigal Lazarev [mailto: ylazarev@gmail.com]
> > Subject: Tomcat 6.0.14 and UTF-8 POST form problem
> >
> > * * Converting from ISO to UTF: *
> > String subj = "קורות חיים של "+new
> > String(((String)nameTextField.getValue()).
> > getBytes("ISO-8859-1"), "UTF-8");
>
> I'm confused: if the text is already in UTF-8, why are you taking an
> apparent text field (already a String, perhaps?), doing a getValue() - a NOP
> for a String, then casting it to a String (another NOP), converting the
> String to a set of Latin-1 (or Hebrew) bytes, and then lying to a String
> constructor by telling it the byte array is in UTF-8?
>
> Even if nameTextField is not a String, there's an awful lot of conflicting
> machinations going on here.
>
> Perhaps I'm missing something...
>
> - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you received
> this in error, please contact the sender and delete the e-mail and its
> attachments from all computers.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
RE: Tomcat 6.0.14 and UTF-8 POST form problem
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Yigal Lazarev [mailto:ylazarev@gmail.com]
> Subject: Tomcat 6.0.14 and UTF-8 POST form problem
>
> * * Converting from ISO to UTF: *
> String subj = "קורות חיים של "+new
> String(((String)nameTextField.getValue()).
> getBytes("ISO-8859-1"), "UTF-8");
I'm confused: if the text is already in UTF-8, why are you taking an apparent text field (already a String, perhaps?), doing a getValue() - a NOP for a String, then casting it to a String (another NOP), converting the String to a set of Latin-1 (or Hebrew) bytes, and then lying to a String constructor by telling it the byte array is in UTF-8?
Even if nameTextField is not a String, there's an awful lot of conflicting machinations going on here.
Perhaps I'm missing something...
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org