You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Adam Gordon <ad...@readytalk.com> on 2007/11/28 00:09:13 UTC
Configuring Struts to use UTF-8 character encoding
Anyone know if there's a configuration parameter somewhere in Struts
1.2.9 that configures the requests to use UTF-8 character encoding?
Everything I've found on the web says that Tomcat uses ISO-8859-1 as the
default character encoding and that the "fix" is to add a filter that
simply sets the character encoding on every request and it works, but it
seems a bit heavy-handed. Reading the Tomcat configuration pages (for
5.5) talks about setting the URIEncoding attribute on the Connector
element but that doesn't appear to have any effect in my sandbox
application. It's possible it's needed for when running Tomcat behind
Apache.
What about adding the afore mentioned code to our webapp's action
servlet or is this basically a glorified filter in the case where a
webapp is really only using Struts - which our webapp is?
Thoughts?
--adam
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Configuring Struts to use UTF-8 character encoding
Posted by Mark McLaren <ma...@gmail.com>.
To muddy the waters a little further! If for some reason (e.g. you are
writing a JSR168 portlet) you cannot use a servlet filters to force
UTF-8 encoding, you can alternatively use a ServletRequestListener.
HTH
Mark
Adam Gordon wrote:
> So, for posterity, we finally got this working. After several days of
> playing around with a sandbox Struts application that worked, but our
> webapp that didn't, we finally realized that the ORDER of the filters
> matters (duh...). We put the character encoding filter first in our
> chain and it fixed everything.
>
> The problem was it was initially #3 in the chain and in filter #2 I
> was reading parameters off the request to look for specific parameters
> to mitigate another bug we'd found in production and apparently,
> whether by design or otherwise, once you read parameters off the
> request setting the character encoding afterwards appears to have no
> effect. As mentioned above, moving the character encoding filter to
> #1 in the chain fixed it.
>
> Adam Gordon wrote:
>> I didn't know that page existed though it's essentially what I wound
>> up doing. My only concern now is that it affects our entire webapp
>> and while QA was going to do a full regression anyway, I'm wondering
>> what potential problems are now lurking in the deep, dark corners of
>> our web forms...
>>
>> Thanks for the link.
>>
>> --adam
>>
>> Ted Husted wrote:
>>
>>> On Nov 28, 2007 10:53 AM, Adam Gordon <ad...@readytalk.com>
>>> wrote:
>>>
>>>> What about the use of a filter to set the character encoding? Is this
>>>> the only way to go for Struts?
>>>>
>>>
>>> I'd say so. It might be possible to add something to the
>>> ActionServlet, but the solution wouldn't be any less "heavy handed"
>>> than using a filter. This sort of thing is why filters were invented
>>> :)
>>>
>>> There's a page on the Tomcat wiki that talks about setting up a UTF
>>> filter, if you haven't seen it.
>>>
>>> * http://wiki.apache.org/tomcat/Tomcat/UTF-8
>>>
>>> -Ted.
>>>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Configuring Struts to use UTF-8 character encoding
Posted by Adam Gordon <ad...@readytalk.com>.
So, for posterity, we finally got this working. After several days of
playing around with a sandbox Struts application that worked, but our
webapp that didn't, we finally realized that the ORDER of the filters
matters (duh...). We put the character encoding filter first in our
chain and it fixed everything.
The problem was it was initially #3 in the chain and in filter #2 I was
reading parameters off the request to look for specific parameters to
mitigate another bug we'd found in production and apparently, whether by
design or otherwise, once you read parameters off the request setting
the character encoding afterwards appears to have no effect. As
mentioned above, moving the character encoding filter to #1 in the chain
fixed it.
Adam Gordon wrote:
> I didn't know that page existed though it's essentially what I wound
> up doing. My only concern now is that it affects our entire webapp
> and while QA was going to do a full regression anyway, I'm wondering
> what potential problems are now lurking in the deep, dark corners of
> our web forms...
>
> Thanks for the link.
>
> --adam
>
> Ted Husted wrote:
>
>> On Nov 28, 2007 10:53 AM, Adam Gordon <ad...@readytalk.com> wrote:
>>
>>> What about the use of a filter to set the character encoding? Is this
>>> the only way to go for Struts?
>>>
>>
>> I'd say so. It might be possible to add something to the
>> ActionServlet, but the solution wouldn't be any less "heavy handed"
>> than using a filter. This sort of thing is why filters were invented
>> :)
>>
>> There's a page on the Tomcat wiki that talks about setting up a UTF
>> filter, if you haven't seen it.
>>
>> * http://wiki.apache.org/tomcat/Tomcat/UTF-8
>>
>> -Ted.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Configuring Struts to use UTF-8 character encoding
Posted by Adam Gordon <ad...@readytalk.com>.
I didn't know that page existed though it's essentially what I wound up doing. My only concern now is that it affects our entire webapp and while QA was going to do a full regression anyway, I'm wondering what potential problems are now lurking in the deep, dark corners of our web forms...
Thanks for the link.
--adam
Ted Husted wrote:
> On Nov 28, 2007 10:53 AM, Adam Gordon <ad...@readytalk.com> wrote:
>
>> What about the use of a filter to set the character encoding? Is this
>> the only way to go for Struts?
>>
>
> I'd say so. It might be possible to add something to the
> ActionServlet, but the solution wouldn't be any less "heavy handed"
> than using a filter. This sort of thing is why filters were invented
> :)
>
> There's a page on the Tomcat wiki that talks about setting up a UTF
> filter, if you haven't seen it.
>
> * http://wiki.apache.org/tomcat/Tomcat/UTF-8
>
> -Ted.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Configuring Struts to use UTF-8 character encoding
Posted by Ted Husted <hu...@apache.org>.
On Nov 28, 2007 10:53 AM, Adam Gordon <ad...@readytalk.com> wrote:
> What about the use of a filter to set the character encoding? Is this
> the only way to go for Struts?
I'd say so. It might be possible to add something to the
ActionServlet, but the solution wouldn't be any less "heavy handed"
than using a filter. This sort of thing is why filters were invented
:)
There's a page on the Tomcat wiki that talks about setting up a UTF
filter, if you haven't seen it.
* http://wiki.apache.org/tomcat/Tomcat/UTF-8
-Ted.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Configuring Struts to use UTF-8 character encoding
Posted by Adam Gordon <ad...@readytalk.com>.
Right, hence my last comment in the second paragraph... Incidentally, I
saw that web page yesterday and was the one who added the anonymous
posting about the URIEncoding attribute not appearing to do anything.
What about the use of a filter to set the character encoding? Is this
the only way to go for Struts?
--adam
Martin Gainty wrote:
> Adam-
>
> remember the URI_Encoding for your mod_jk connector
> http://confluence.atlassian.com/display/DOC/Configuring+Tomcat's+URI+encodin
> g
>
> M--
> ----- Original Message -----
> From: "Adam Gordon" <ad...@readytalk.com>
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Sent: Tuesday, November 27, 2007 6:09 PM
> Subject: Configuring Struts to use UTF-8 character encoding
>
>
>
>> Anyone know if there's a configuration parameter somewhere in Struts
>> 1.2.9 that configures the requests to use UTF-8 character encoding?
>>
>> Everything I've found on the web says that Tomcat uses ISO-8859-1 as the
>> default character encoding and that the "fix" is to add a filter that
>> simply sets the character encoding on every request and it works, but it
>> seems a bit heavy-handed. Reading the Tomcat configuration pages (for
>> 5.5) talks about setting the URIEncoding attribute on the Connector
>> element but that doesn't appear to have any effect in my sandbox
>> application. It's possible it's needed for when running Tomcat behind
>> Apache.
>>
>> What about adding the afore mentioned code to our webapp's action
>> servlet or is this basically a glorified filter in the case where a
>> webapp is really only using Struts - which our webapp is?
>>
>> Thoughts?
>>
>> --adam
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org