我试图像这样在IE链接中发送希伯来语参数:
localhost:8080/test?g=שלום
שלום=希伯来文
我在tomcat server.xml中设置:
useBodyEncodingForURI="true" URIEncoding="UTF-8"
并在我的web.xml中使用此过滤器:
<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(){}
}
但是当我用参数调试我的servlet时,我得到了胡言乱语 像这样: OOD-à
我试过用这个:
String str = new String(text.getBytes("UTF-8"), "Windows-1255");
但得到了“????”
和
String str = new String(text.getBytes("UTF-8"), "ISO-8859-1");
得到了“øÃ'ð-Ô
我能做什么?