That filter will work with struts 1. Just be sure it's early in the filter
chain before anyone is reading the request.
I always make it the first filter.

On Mon, Jul 27, 2009 at 4:23 PM, Ashish Kulkarni <
ashish.kulkarn...@gmail.com> wrote:

> HiI am using struts 1.2.6 and not yes in struts 2,
> So should i just put in a general filter to do encoding?
>
> Ashish
>
> On Mon, Jul 27, 2009 at 4:10 PM, Greg Lindholm <greg.lindh...@gmail.com
> >wrote:
>
> > On Mon, Jul 27, 2009 at 3:34 PM, Ashish Kulkarni <
> > ashish.kulkarn...@gmail.com> wrote:
> >
> > > HiI have a jsp page which displays data in UTF-8 encoding, there is a
> > input
> > > text field, when user enter japanese characters in this input text and
> > data
> > > is transferred to Actionclass i get junk value,
> > >
> > > How do i handle japanese characters in ActionClass, do i have to do
> > > anything
> > > special in servlet or in JSP?
> > >
> > > I did try to put request.setCharacterEncoding("UTF-8"); in my Action
> > class,
> > > but still does not work.
> > >
> > > JSP page displays proper japanese characters as it is uses UTF-8 for
> > > encoding,
> > >
> > > Is there a solution which will work for tomcat, weblogic and websphere
> > > application server? or is encoding handled seperately by different app
> > > servers
> > >
> >
> > Setting character encoding in your action is too late, the parameters
> have
> > already been read from the request.
> > You need to set the character encoding in a filter that runs before the
> > struts2 filter.
> >
> > There is a simple filter that will do it.  You just need to add this
> filter
> > to your web.xml before the struts2 filter.
> >
> > public class CharacterEncodingFilter implements Filter
> > {
> >    public void doFilter(ServletRequest request, ServletResponse response,
> > FilterChain next)
> >        throws IOException, ServletException
> >    {
> >        String encoding = request.getCharacterEncoding();
> >        if (encoding == null || encoding.length() == 0)
> >        {
> >            request.setCharacterEncoding("UTF-8");
> >        }
> >
> >        next.doFilter(request, response);
> >    }
> >
> > }
> >
>

Reply via email to