tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mariusz Wiktorczyk <>
Subject Re: Character encoding for form submissions
Date Fri, 04 Apr 2003 07:13:36 GMT
Olny filter can help you.
But remember:
------------ from api ---------


public void setCharacterEncoding(java.lang.String env)

    Overrides the name of the character encoding used in the body of
    this request. This method must be called prior to reading request
parameters or reading input using getReader().


Here is code:
public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain chain)
    throws IOException, ServletException {

        // Conditionally select and set the character encoding to be used
        if (request.getCharacterEncoding() == null) {
            if (encoding != null)
        // Pass control on to the next filter
        chain.doFilter(request, response);


public void init(FilterConfig filterConfig) throws ServletException {

    this.filterConfig = filterConfig;
        this.encoding = filterConfig.getInitParameter("encoding");

public void destroy() {

        this.encoding = null;
        this.filterConfig = null;


and web.xml
    <filter-name>Set Character Encoding</filter-name>
    <filter-name>Set Character Encoding</filter-name>

I had the same problems and this filter has helped me.

Morris Jones wrote:

>I've been researching this for a while.
>I'm using Tomcat 4.1.18, and struts 1.0.2.
>My app is successfully handling Unicode characters -- in all the actions,
>stored in the database, displayed on the HTML pages, using charset=UTF-8.
>But the only way I can find to get form data into Unicode in my form bean
>is by manually transcoding the UTF-8 strings that come in into Unicode.
>I'm led to believe that adding a filter to my app that calls
>ServletRequest.setCharacterEncoding("UTF-8") will automatically transcode
>the form data (from POST) into Unicode.  I can set breakpoints in
>the filter and see that setCharacterEncoding() is being called, and
>breakpoints in my form to see that the UTF-8 string from the form is
>being set untouched.
>What's the deal?  Is it really necessary to add conversion code to all of
>my form beans?

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message