0

I tried to send hebrew paramaters in link on IE like this:

localhost:8080/test?g=שלום

שלום = Hebrew text

I set in my tomcat server.xml:

useBodyEncodingForURI="true" URIEncoding="UTF-8"

and in my web.xml this filter:

<filter>
    <display-name>set character encoding</display-name>
    <filter-name>setCharacterEncodingFilter</filter-name>
    <filter-class>com.Moh.SetCharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param> 
</filter>

<filter-mapping>
    <filter-name>setCharacterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

com.Moh.SetCharacterEncodingFilter :

package com.Moh;
import java.io.IOException;
import javax.servlet.*;

/**
 * Set the character encoding of the request to as set in "encoding"
 * this should be done before the request is accessed.
 */
public class SetCharacterEncodingFilter implements Filter {
    private String encoding;

    public void init(FilterConfig config) throws ServletException{
        encoding = config.getInitParameter("requestEncoding");
        if( encoding==null ) encoding="UTF-8";
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain next)
            throws IOException, ServletException{
        // Respect the client-specified character encoding
        // (see HTTP specification section 3.4.1)
        if(null == request.getCharacterEncoding())
            request.setCharacterEncoding(encoding);
        /**
         * Set the default response content type and encoding
         */
        response.setContentType("text/html; charset=UTF-8");
        response.setCharacterEncoding("UTF-8");
        next.doFilter(request, response);
    }

    public void destroy(){}
}

but when i debug my servlet with the paramaters i got gibberish like this: øôð-à

I tried use this:

String str = new String(text.getBytes("UTF-8"), "Windows-1255"); but got "????"

and

String str = new String(text.getBytes("UTF-8"), "ISO-8859-1"); and got "øôð-Ã"

what can i do?

Danilo Cândido
  • 408
  • 1
  • 5
  • 18
kfir
  • 732
  • 10
  • 22
  • 2
    You shouldn't have Hebrew in the link. It should be encoded there already. Don't trust IE to encode it in the correct encoding. – RealSkeptic Aug 14 '17 at 13:20
  • @RealSkeptic tnx for your answer but i cant encode the text in the link, this is a third party software that send the links like that and can't change it – kfir Aug 14 '17 at 13:23
  • 1
    AFAIK browsers will encode url parameters using URLencoding, i.e. your hebrew parameter would then be encoded as `%D7%A9%D7%9C%D7%95%D7%9D`. Thus you could try to decode that using `URLDecoder.decode( parameter, "UTF-8")`. – Thomas Aug 14 '17 at 13:23
  • Which version of IE? – Novaterata Aug 14 '17 at 13:24
  • @Novaterata all of them... and in chrome its working perfect because its encode automatic or something like that – kfir Aug 14 '17 at 13:24
  • So you need to check which encoding the software uses. Please include a real example URL (already encoded). – RealSkeptic Aug 14 '17 at 13:25
  • Have a look at this https://blogs.msdn.microsoft.com/ieinternals/2014/04/22/unicode-in-url-changes-for-ie11/ – Novaterata Aug 14 '17 at 13:26
  • And this https://stackoverflow.com/questions/18220057/encoding-of-query-string-parameters-in-ie10/18220123#18220123 – Novaterata Aug 14 '17 at 13:28
  • @Novaterata ok tnx i will look that – kfir Aug 14 '17 at 13:29
  • @Novaterata your link solved my problem, i set in IE settings to send utf8 query string and its worked – kfir Aug 14 '17 at 13:46

0 Answers0