You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by jack dimas <ja...@hotmail.com> on 2002/05/09 17:21:47 UTC

Parameter Parser: Charset encoding problem

Hi guys

I am submitting greek characters (iso-8859-7) to turbine. I use

$data.getParameters().getString("form1_field")

to display these characters in a turbine template but in the place of the 
original characters I get question marks (????????) How can I make turbine 
to understand that I'm submitting in this specific charset? Must I do a 
specific configuration to the Parameter Parser?

I have installed tdk 2.1 and created a demo app using mysql for database. 
However I don't use the DB for the above example.

_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Parameter Parser: Charset encoding problem

Posted by Maciej Leks <ml...@zeus.polsl.gliwice.pl>.
Hello jack,

I think I can help you!

First off all you must know that character encoding must be set in two
places (I pass over the database encondig settings):
1) In the TR.properties
2) You must deliver character encoding filter for the Tomcat server

Ad 1)
a)In the TR.properties find section concering Velocity service settings
b)Find line:
       services.VelocityService.input.encoding
c) Now, set the proper encoding standard for input, i.e
       services.VelocityService.input.encoding=iso-8859-7
d) Find the line
        locale.default.charset
e) Now, set the proper encoding standard for content type, i.e
       locale.default.charset=iso-8859-7
d) Now restart tomcat server to reload the TR.properies settings

Observe your greek character on the screen, if you still have ???????
you must add tomcat filter!

Ad 2)
a) Write a class which implements the javax.servlet.Filter interface
b) In the web.xml file add these lines beetwen <web-app> and </web-app>

    <filter>
        <filter-name>Set Character Encoding</filter-name>
        <filter-class>my.mygreekproject.MyFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>iso-8859-7</param-value>
        </init-param>
    </filter>
        <filter-mapping>
        <filter-name>Set Character Encoding</filter-name>
        <servlet-name>MyGreekServeltName</servlet-name>
    </filter-mapping>
c) Now you can reload the application

What you see?

For those of you who are not familiar with Filter interface I added
the sample class implementing the Filter interface.

Best regards!

<CODE START>
package my.mygreekproject;

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.UnavailableException;

/**
 * @author Craig McClanahan revision Maciej Leks
 * @version $Revision: 1.1 $ $Date: 2001/07/24 00:26:55 $
 */


public class MyFilter implements Filter
{
    /**
     * The default character encoding to set for requests that pass through
     * this filter.
     */
    protected String encoding = null;


    /**
     * The filter configuration object we are associated with.  If this value
     * is null, this filter instance is not currently configured.
     */
    protected FilterConfig filterConfig = null;


    // --------------------------------------------------------- Public Methods


    /**
     * Take this filter out of service.
     */
    public void destroy() {

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

    }


    /**
     * Select and set (if specified) the character encoding to be used to
     * interpret request parameters for this request.
     *
     * @param request The servlet request we are processing
     * @param result The servlet response we are creating
     * @param chain The filter chain we are processing
     *
     * @exception IOException if an input/output error occurs
     * @exception ServletException if a servlet error occurs
     */
    public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain chain)
        throws IOException, ServletException {

        // Select and set (if needed) the character encoding to be used
        String encoding = selectEncoding(request);
          if (encoding != null)
            request.setCharacterEncoding(encoding);

        // Pass control on to the next filter
        chain.doFilter(request, response);

    }


    /**
     * Place this filter into service.
     *
     * @param filterConfig The filter configuration object
     */
    public void init(FilterConfig filterConfig) {

        this.filterConfig = filterConfig;
        this.encoding = filterConfig.getInitParameter("encoding");
        System.out.println("Filter alive - encoding set:" +this.encoding);

    }    
    public void setFilterConfig(FilterConfig filterConfig) {

        this.filterConfig = filterConfig;
        this.encoding = filterConfig.getInitParameter("encoding");
        System.out.println("Filter alive - encoding set:" +this.encoding);

    }
    public FilterConfig getFilterConfig() {
        return filterConfig;
    }


    // ------------------------------------------------------ Protected Methods


    /**
     * Select an appropriate character encoding to be used, based on the
     * characteristics of the current request and/or filter initialization
     * parameters.  If no character encoding should be set, return
     * <code>null</code>.
     * <p>
     * The default implementation unconditionally returns the value configured
     * by the <strong>encoding</strong> initialization parameter for this
     * filter.
     *
     * @param request The servlet request we are processing
     */
    protected String selectEncoding(ServletRequest request) {

        return (this.encoding);

    }
}
<CODE END>




jd> I am submitting greek characters (iso-8859-7) to turbine. I use

jd> $data.getParameters().getString("form1_field")

jd> to display these characters in a turbine template but in the place of the 
jd> original characters I get question marks (????????) How can I make turbine 
jd> to understand that I'm submitting in this specific charset? Must I do a 
jd> specific configuration to the Parameter Parser?

jd> I have installed tdk 2.1 and created a demo app using mysql for database. 
jd> However I don't use the DB for the above example.

jd> _________________________________________________________________
jd> Chat with friends online, try MSN Messenger: http://messenger.msn.com


jd> --
jd> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
jd> For additional commands, e-mail: <ma...@jakarta.apache.org>





______________________________________
 Leksiu (mleks@zeus.polsl.gliwice.pl)


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>