You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mike Erickson <mi...@shaw.ca> on 2003/12/04 19:11:35 UTC
ContentType problem
I'm using Jboss 3.2, Tomcat 4.1 and Struts 1.1 (including Tiles) and am
unable to set the encoding to utf-8.
I've tried the following:
1) set the contenttype within the controller configuration in
struts-config.xml
contentType="text/html;charset=UTF-8"
2) set response header in Action class
lResponse.setContentType("text/html; charset=UTF-8");
3) set page directive within jsp (in the tile layout file)
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="utf-8" %>
4) set response header within jsp (in the tile layout file)
<% response.setContentType("text/html;charset=UTF-8"); %>
Every time the encoding is iso-8859-1. The generated _jsp.java file contains
the line
response.setContentType("text/html;charset=ISO-8859-1");
and I've sniffed the request to confirm the headers. I can create a plain
servlet and set the contenttype to utf-8 without any problems.
Any suggestions? Anyone get tiles to return utf-8? I shouldn't have to use a
filter to fix this..
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: ContentType problem
Posted by Mike Erickson <mi...@shaw.ca>.
> Try putting the page contenttype declaration as the first line in every
tile. It has to be done before > any output is sent to response.
Thanks but I tried this and it doesn't work, something seems to over-ride my
settings.
I finally found a way of getting this to work. Before, no matter where I put
the contenttype code, it seemed to get over-written. Since you should not be
able to change the headers after the outputstream has been used, I tried
setting it and then calling flush which seems to work. I still don't
understand why my original code didn't work but I'm getting the correct
encoding now.
// Old way - didn't work
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="utf-8" %>
<%@ include file="/common/include/init.jsp" %>
.. Content ..
// New way - works
<%@ include file="/common/include/headers.jsp" %>
<%@ include file="/common/include/init.jsp" %>
.. Content ..
// headers.jsp
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="utf-8" %>
<% out.flush(); %>
// init.jsp
Tag libs & resource/locale init code, no headers are set
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: ContentType problem
Posted by Adam Hardy <ah...@cyberspaceroad.com>.
On 12/04/2003 07:11 PM Mike Erickson wrote:
> I'm using Jboss 3.2, Tomcat 4.1 and Struts 1.1 (including Tiles) and am
> unable to set the encoding to utf-8.
> I've tried the following:
> 1) set the contenttype within the controller configuration in
> struts-config.xml
> contentType="text/html;charset=UTF-8"
> 2) set response header in Action class
> lResponse.setContentType("text/html; charset=UTF-8");
> 3) set page directive within jsp (in the tile layout file)
> <%@ page contentType="text/html;charset=UTF-8" pageEncoding="utf-8" %>
> 4) set response header within jsp (in the tile layout file)
> <% response.setContentType("text/html;charset=UTF-8"); %>
>
> Every time the encoding is iso-8859-1. The generated _jsp.java file contains
> the line
> response.setContentType("text/html;charset=ISO-8859-1");
> and I've sniffed the request to confirm the headers. I can create a plain
> servlet and set the contenttype to utf-8 without any problems.
>
> Any suggestions? Anyone get tiles to return utf-8? I shouldn't have to use a
> filter to fix this..
Try putting the page contenttype declaration as the first line in every
tile. It has to be done before any output is sent to response.
Adam
--
struts 1.1 + tomcat 5.0.16 + java 1.4.2
Linux 2.4.20 Debian
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org