Hi Lubos,

I received your suggested 'filter' solution a couple of months ago in
response to a problem I was having with tapestry and UTF-8, I didn't use it
afterwards as I just used an image instead of the desired text, but now that
I'm internationalising my web application, I'd like to fix this problem for
once and for all.

I've tried/attempted your solution, but to no avail, perhaps you could take
a quick look at my implementation and check to see that I haven't done
something stupid!

Regards, Brian.

In web.xml (just the relevant entries are shown)
<web-app>
   <context-param>
       <param-name>PARAMETER_ENCODING</param-name>
       <param-value>UTF-8</param-value>
   </context-param>

   <filter>
       <filter-name>meta-filter</filter-name>
       <filter-class>com.mycompany.MetaFilter</filter-class>
   </filter>

   <filter-mapping>
       <servlet-name>my_project</servlet-name>
       <filter-name>meta-filter</filter-name>
   </filter-mapping>

    <servlet-mapping>
        <servlet-name>my_project</servlet-name>
        <url-pattern>/app</url-pattern>
    </servlet-mapping>

</web-app>

The filter class I created based on your example . . .


package com.mycompany;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

public class MetaFilter implements Filter {

   FilterConfig config;

   public void init(FilterConfig config)
   {
       this.config = config;
   }

    public void doFilter(ServletRequest servletRequest, ServletResponse
            servletResponse,
                       FilterChain filterChain) throws IOException,
ServletException {
             try  {
                 HttpServletRequest httpServletRequest =
(HttpServletRequest)
            servletRequest;
                       servletRequest.setCharacterEncoding("UTF-8");
                       servletResponse.setContentType( "text/html;
charset=UTF-8" );
             } finally {
                 //do nothing;
             }
    }

   public void destroy() {

   }


}

I'm sure I missing something in the above, the httpServletRequest I create
is never read/used, perhaps you could give me some pointers as to how I
would finish off this class?

Thanks again for all your help . . .

On 1/31/06, Lubos and Alena Pochman <[EMAIL PROTECTED]> wrote:

I had the same problem with Tapestry 3.02 and I think it is still in 4.0.
Somehow
Tapestry doesnt' set up content type properly. Looking at html source from
Tapestry,
the <meta> for content type is not the first <meta> but the second <meta>
in
the <header>.
I have read somewhere, that content type <meta> must be the first in
<header> otherwise it is ignore.

I came with workaround. I use web-app <filter> and in that I force utf-8:

public void doFilter(ServletRequest servletRequest, ServletResponse
servletResponse,
            FilterChain filterChain) throws IOException, ServletException
{
  try  {
      HttpServletRequest httpServletRequest = (HttpServletRequest)
servletRequest;
            servletRequest.setCharacterEncoding("UTF-8");
            servletResponse.setContentType( "text/html; charset=UTF-8" );


It is ugly but it works.

Lubos


Reply via email to