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?