You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Susie Derkins <so...@yahoo.ca> on 2004/07/12 22:35:33 UTC

Problems with Tomcat, Struts/Tiles, and encoding

Hi list,

I�m using Tiles with Catalina (4.1.29 on Linus and
Windows). and I�m having problems setting the
response�s encoding to UTF-8.

I added:
<%@ page contentType="text/html;charset=UTF-8"
pageEncoding-"UTF-8" %>
to all my JSP pages � tiles and layouts. It is the
first line of each page.

So now, all my JSPs call 
ApplicationHttpResponse.setContentType *before*
accessing the page�s writer.

Here is the code for setContentType:
public void setContentType(String type) {
        if (!included)
            getResponse().setContentType(type);
}

The problem is that the body of setContentType is
never executed because each time a JSP calls it,
included is true (I verified by stepping through the
code with a debugger), which means we are inside a
RequestDispatcher.include(). My guess is that it's
Tiles or Struts that causes the request to be dispatch
via  RequestDispatcher.include.

I tried to set the response�s content type in a
filter,  but when I check in my custom tags,
pageContext.getResponse().pageContext.getResponse()
always returns ISO-8859-1, Tomcat�s default encoding.

Setting the encoding in a JSP works fine as long as
Struts/Tiles are not involved.

Can somebody please shed some light on this? Do you
know of another way of setting the encoding, that can
occur before the JSPs are processed?
I want to avoid having to build a custom version of
Tomcat with UTF-8 as the default encoding. 

Thanks for your time,

Sophia.

______________________________________________________________________ 
Post your free ad now! http://personals.yahoo.ca

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Problems with Tomcat, Struts/Tiles, and encoding

Posted by "Ruth, Brice" <br...@fiskars.com>.
I have a Struts/Tiles application running on Tomcat 4.1.x and Tomcat 5.x 
with UTF-8 encoding (Polish & Russian character sets, particularly) - I 
didn't have to do anything special for the response encoding, only for 
the request encoding. Here's what I put at the top of my JSPs:

<%@ page contentType="text/html; charset=UTF-8" %>

That seems to do the trick for me. The character encoding for the page 
is UTF-8 regardless if I'm requesting a JSP directly, or going through 
an Action.

The entire www.fiskars.com site is Struts/Tiles driven, you can check 
out http://www.fiskars.com/ru_RU/index.do in particular to see the RU 
character set being used (in UTF-8 encoding).

Like I said, the only special thing concerns request encoding ... a 
filter needed to be installed for that. How are you determining that the 
encoding being sent the the browser isn't UTF-8? Garbage characters 
alone won't be a good indication ... in Firefox, I go to the "View" menu 
pop-out the "Character Encoding" menu ... make sure that its set to 
UTF-8. If it is and you're still getting garbage characters, you may not 
be saving the JSP files as UTF-8 in your editor. In Eclipse, for 
instance, you need to specify that the file is UTF-8 in the file's 
properties (or globally for all files) .. if you don't, it will look 
like the characters are being inserted correctly, but when Eclipse saves 
the file, it converts all the characters to ISO-8859-1 which will look 
like garbage in the browser, even if the encoding is set to UTF-8.

Hope some of this helps!

Brice

Susie Derkins wrote:

>Hi list,
>
>I’m using Tiles with Catalina (4.1.29 on Linus and
>Windows). and I’m having problems setting the
>response’s encoding to UTF-8.
>
>I added:
><%@ page contentType="text/html;charset=UTF-8"
>pageEncoding-"UTF-8" %>
>to all my JSP pages – tiles and layouts. It is the
>first line of each page.
>
>So now, all my JSPs call 
>ApplicationHttpResponse.setContentType *before*
>accessing the page’s writer.
>
>Here is the code for setContentType:
>public void setContentType(String type) {
>        if (!included)
>            getResponse().setContentType(type);
>}
>
>The problem is that the body of setContentType is
>never executed because each time a JSP calls it,
>included is true (I verified by stepping through the
>code with a debugger), which means we are inside a
>RequestDispatcher.include(). My guess is that it's
>Tiles or Struts that causes the request to be dispatch
>via  RequestDispatcher.include.
>
>I tried to set the response’s content type in a
>filter,  but when I check in my custom tags,
>pageContext.getResponse().pageContext.getResponse()
>always returns ISO-8859-1, Tomcat’s default encoding.
>
>Setting the encoding in a JSP works fine as long as
>Struts/Tiles are not involved.
>
>Can somebody please shed some light on this? Do you
>know of another way of setting the encoding, that can
>occur before the JSPs are processed?
>I want to avoid having to build a custom version of
>Tomcat with UTF-8 as the default encoding. 
>
>Thanks for your time,
>
>Sophia.
>
>______________________________________________________________________ 
>Post your free ad now! http://personals.yahoo.ca
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>  
>

-- 
Brice Ruth, Sr. IT Analyst
Fiskars Brands Inc
http://www.fiskarsbrands.com/


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org