You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by ruphus13 <ru...@gmail.com> on 2006/11/18 22:52:37 UTC

Re: Response encoding problem

Hi - I'm trying to show utf-8 data in the browser from my jsp page.
When the page renders, its character encoding is iso-8859-1, according
to the browser.  The http
response headers have the same encoding (iso-8859-1).

Here's what's been done thus far:

1) meta tag set as follows:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

2) jsp page encoding directive issued at the start of the jsp page.
<%@page contentType="text/html; charset=UTF-8"%>

3) Generated jsp page has the following java code, as a consequence:
try {
     _jspxFactory = JspFactory.getDefaultFactory();
     response.setContentType("text/html; charset=UTF-8");
     pageContext = _jspxFactory.getPageContext(this, request, response,
               null, false, 8192, true);
     application = pageContext.getServletContext();
     config = pageContext.getServletConfig();
     out = pageContext.getOut();
     _jspx_out = out;
...
4) When I save the page as an html file and open it as an html file in
the browser, it renders correctly (due to the meta tag and no http
headers), which is expected.

5) Manually changing the page encoding in firefox results in the page
being rendered correctly.

6) Also set utf-8 in the connector settings in tomcat/conf/server.xml
(for GETs?)

<Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
              port="8080" minProcessors="5" maxProcessors="75"
              URIEncoding="UTF-8" useBodyEncodingForURI="true"
              enableLookups="true" redirectPort="8443"
              acceptCount="100" debug="0" connectionTimeout="20000"
              useURIValidationHack="false" disableUploadTimeout="true" />

7) Set utf-8 in web.xml as follows:
<servlet>
       <servlet-name>jsp</servlet-name>
       <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
       <init-param>
           <param-name>javaEncoding</param-name>
           <param-value>UTF8</param-value>
       </init-param>
...

However, the page still shows up as iso-8859-1 (in firefox and IE),
and viewing the response headers using a 3rd party plugin shows the
content-type as ISO-8859-1

Tomcat: 4.1.31
JDK: 1.4.2

What I'm hoping to learn is how to set the http response headers
correctly.  It seems that the generated java code is doing the right
thing.  However, the response header is still jacked...

Any help will be very, very much appreciated!  I've gone through
several articles on Goog as well as the tomcat mailing list... The
brick wall is getting bloodier, and I'm getting woozy from the
pounding...

---------------------------------------------------------------------
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: Response encoding problem

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Enrico Donelli [mailto:enrico.donelli@gmail.com] 
> Subject: Re: Response encoding problem
> 
> I don't know if this helps, but I had a similar problems once, and it
> was caused by a filter which was reading a parameter from the request.
> This first access set the encoding to 8859-1, overriding all my
> following settings.

Also, I have a vague memory that the JSP source itself must be stored in
UTF-8, if there are any non-ASCII characters in it.  Might want to check
the archives for that.

 - 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: Response encoding problem

Posted by Enrico Donelli <en...@gmail.com>.
I don't know if this helps, but I had a similar problems once, and it
was caused by a filter which was reading a parameter from the request.
This first access set the encoding to 8859-1, overriding all my
following settings.

I would start from this ... hope this helps.
Good luck!

Enrico

On 18/11/06, ruphus13 <ru...@gmail.com> wrote:
> Hi - I'm trying to show utf-8 data in the browser from my jsp page.
> When the page renders, its character encoding is iso-8859-1, according
> to the browser.  The http
> response headers have the same encoding (iso-8859-1).
>
> Here's what's been done thus far:
>
> 1) meta tag set as follows:
> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
>
> 2) jsp page encoding directive issued at the start of the jsp page.
> <%@page contentType="text/html; charset=UTF-8"%>
>
> 3) Generated jsp page has the following java code, as a consequence:
> try {
>      _jspxFactory = JspFactory.getDefaultFactory();
>      response.setContentType("text/html; charset=UTF-8");
>      pageContext = _jspxFactory.getPageContext(this, request, response,
>                null, false, 8192, true);
>      application = pageContext.getServletContext();
>      config = pageContext.getServletConfig();
>      out = pageContext.getOut();
>      _jspx_out = out;
> ...
> 4) When I save the page as an html file and open it as an html file in
> the browser, it renders correctly (due to the meta tag and no http
> headers), which is expected.
>
> 5) Manually changing the page encoding in firefox results in the page
> being rendered correctly.
>
> 6) Also set utf-8 in the connector settings in tomcat/conf/server.xml
> (for GETs?)
>
> <Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
>               port="8080" minProcessors="5" maxProcessors="75"
>               URIEncoding="UTF-8" useBodyEncodingForURI="true"
>               enableLookups="true" redirectPort="8443"
>               acceptCount="100" debug="0" connectionTimeout="20000"
>               useURIValidationHack="false" disableUploadTimeout="true" />
>
> 7) Set utf-8 in web.xml as follows:
> <servlet>
>        <servlet-name>jsp</servlet-name>
>        <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
>        <init-param>
>            <param-name>javaEncoding</param-name>
>            <param-value>UTF8</param-value>
>        </init-param>
> ...
>
> However, the page still shows up as iso-8859-1 (in firefox and IE),
> and viewing the response headers using a 3rd party plugin shows the
> content-type as ISO-8859-1
>
> Tomcat: 4.1.31
> JDK: 1.4.2
>
> What I'm hoping to learn is how to set the http response headers
> correctly.  It seems that the generated java code is doing the right
> thing.  However, the response header is still jacked...
>
> Any help will be very, very much appreciated!  I've gone through
> several articles on Goog as well as the tomcat mailing list... The
> brick wall is getting bloodier, and I'm getting woozy from the
> pounding...
>
> ---------------------------------------------------------------------
> 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
>
>

---------------------------------------------------------------------
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: Response encoding problem

Posted by ruphus13 <ru...@gmail.com>.
Thanks for all your help.  Here's some more data and an update:

1) The jsp is basically displaying unicode strings from the db.  So,
there is no other data other than a directive to print the string from
the db.
2) Running a direct query from the db shows the string correctly.  The
db is mysql.  The table type is innodb.  The charset has been set to
utf-8.
3) Currently, the locale is set as follows:

<% java.util.Locale locale = request.getLocale();
    String userLocale = locale.toString(); %>
<fmt:setLocale value = "${userLocale}"/>

When I changed that to force the locale to utf-8, the browser
(firefox) was showing the page encoding as utf-8.  The response
headers were utf-8.  However, the string now was getting 'double
encoded', and was still showing up jacked.

I will try the filters route, and will try and see what is getting
passed in and out.
Will also try working with a very basic jsp page that just prints out
a static string to see how things are flowing through the app.

Any links on the 'best practices' to follow for such a scenario
(showing utf-8 strings from the db)?

Thanks in advance!


On 11/18/06, Bill Barker <wb...@wilshire.com> wrote:
> If your JSP page is being included from another servlet, then it won't be
> allowed to set the content-type (or charset) of the response.  Just a wild
> guess here :).
>
> The HTTP/1.1 RFC states that the character encoding of the headers is
> iso-8859-1.  That is why Tomcat doesn't provide an option to change it.
>
> "ruphus13" <ru...@gmail.com> wrote in message
> news:d28d676c0611181352x13f22e0au455406dbd6284a1e@mail.gmail.com...
> > Hi - I'm trying to show utf-8 data in the browser from my jsp page.
> > When the page renders, its character encoding is iso-8859-1, according
> > to the browser.  The http
> > response headers have the same encoding (iso-8859-1).
> >
> > Here's what's been done thus far:
> >
> > 1) meta tag set as follows:
> > <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
> >
> > 2) jsp page encoding directive issued at the start of the jsp page.
> > <%@page contentType="text/html; charset=UTF-8"%>
> >
> > 3) Generated jsp page has the following java code, as a consequence:
> > try {
> >     _jspxFactory = JspFactory.getDefaultFactory();
> >     response.setContentType("text/html; charset=UTF-8");
> >     pageContext = _jspxFactory.getPageContext(this, request, response,
> >               null, false, 8192, true);
> >     application = pageContext.getServletContext();
> >     config = pageContext.getServletConfig();
> >     out = pageContext.getOut();
> >     _jspx_out = out;
> > ...
> > 4) When I save the page as an html file and open it as an html file in
> > the browser, it renders correctly (due to the meta tag and no http
> > headers), which is expected.
> >
> > 5) Manually changing the page encoding in firefox results in the page
> > being rendered correctly.
> >
> > 6) Also set utf-8 in the connector settings in tomcat/conf/server.xml
> > (for GETs?)
> >
> > <Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
> >              port="8080" minProcessors="5" maxProcessors="75"
> >              URIEncoding="UTF-8" useBodyEncodingForURI="true"
> >              enableLookups="true" redirectPort="8443"
> >              acceptCount="100" debug="0" connectionTimeout="20000"
> >              useURIValidationHack="false" disableUploadTimeout="true" />
> >
> > 7) Set utf-8 in web.xml as follows:
> > <servlet>
> >       <servlet-name>jsp</servlet-name>
> >       <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
> >       <init-param>
> >           <param-name>javaEncoding</param-name>
> >           <param-value>UTF8</param-value>
> >       </init-param>
> > ...
> >
> > However, the page still shows up as iso-8859-1 (in firefox and IE),
> > and viewing the response headers using a 3rd party plugin shows the
> > content-type as ISO-8859-1
> >
> > Tomcat: 4.1.31
> > JDK: 1.4.2
> >
> > What I'm hoping to learn is how to set the http response headers
> > correctly.  It seems that the generated java code is doing the right
> > thing.  However, the response header is still jacked...
> >
> > Any help will be very, very much appreciated!  I've gone through
> > several articles on Goog as well as the tomcat mailing list... The
> > brick wall is getting bloodier, and I'm getting woozy from the
> > pounding...
> >
> > ---------------------------------------------------------------------
> > 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
> >
> >
>
>
>
>
> ---------------------------------------------------------------------
> 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
>
>

---------------------------------------------------------------------
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: Response encoding problem

Posted by Bill Barker <wb...@wilshire.com>.
If your JSP page is being included from another servlet, then it won't be 
allowed to set the content-type (or charset) of the response.  Just a wild 
guess here :).

The HTTP/1.1 RFC states that the character encoding of the headers is 
iso-8859-1.  That is why Tomcat doesn't provide an option to change it.

"ruphus13" <ru...@gmail.com> wrote in message 
news:d28d676c0611181352x13f22e0au455406dbd6284a1e@mail.gmail.com...
> Hi - I'm trying to show utf-8 data in the browser from my jsp page.
> When the page renders, its character encoding is iso-8859-1, according
> to the browser.  The http
> response headers have the same encoding (iso-8859-1).
>
> Here's what's been done thus far:
>
> 1) meta tag set as follows:
> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
>
> 2) jsp page encoding directive issued at the start of the jsp page.
> <%@page contentType="text/html; charset=UTF-8"%>
>
> 3) Generated jsp page has the following java code, as a consequence:
> try {
>     _jspxFactory = JspFactory.getDefaultFactory();
>     response.setContentType("text/html; charset=UTF-8");
>     pageContext = _jspxFactory.getPageContext(this, request, response,
>               null, false, 8192, true);
>     application = pageContext.getServletContext();
>     config = pageContext.getServletConfig();
>     out = pageContext.getOut();
>     _jspx_out = out;
> ...
> 4) When I save the page as an html file and open it as an html file in
> the browser, it renders correctly (due to the meta tag and no http
> headers), which is expected.
>
> 5) Manually changing the page encoding in firefox results in the page
> being rendered correctly.
>
> 6) Also set utf-8 in the connector settings in tomcat/conf/server.xml
> (for GETs?)
>
> <Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
>              port="8080" minProcessors="5" maxProcessors="75"
>              URIEncoding="UTF-8" useBodyEncodingForURI="true"
>              enableLookups="true" redirectPort="8443"
>              acceptCount="100" debug="0" connectionTimeout="20000"
>              useURIValidationHack="false" disableUploadTimeout="true" />
>
> 7) Set utf-8 in web.xml as follows:
> <servlet>
>       <servlet-name>jsp</servlet-name>
>       <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
>       <init-param>
>           <param-name>javaEncoding</param-name>
>           <param-value>UTF8</param-value>
>       </init-param>
> ...
>
> However, the page still shows up as iso-8859-1 (in firefox and IE),
> and viewing the response headers using a 3rd party plugin shows the
> content-type as ISO-8859-1
>
> Tomcat: 4.1.31
> JDK: 1.4.2
>
> What I'm hoping to learn is how to set the http response headers
> correctly.  It seems that the generated java code is doing the right
> thing.  However, the response header is still jacked...
>
> Any help will be very, very much appreciated!  I've gone through
> several articles on Goog as well as the tomcat mailing list... The
> brick wall is getting bloodier, and I'm getting woozy from the
> pounding...
>
> ---------------------------------------------------------------------
> 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
>
> 




---------------------------------------------------------------------
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