我在一个 jsp 中有一个变量,值是中文的要作为参数传到 润乾报表中,可是进去的值总是乱码,这个报表认的是 gbk 编码,如: String title ="我的中文报表" ;
title = new String(title.getBytes("UTF-8"),"GBK");
只有这时里面才会显示一部分中文, 请问明白编码的高手,
除了这种转码方式,还有哪些转码方式, 我现在要一个一个一个的试,没办法,别的配置不能改的呀, help me !!!!!!!!!!!!
title = new String(title.getBytes("UTF-8"),"GBK");
只有这时里面才会显示一部分中文, 请问明白编码的高手,
除了这种转码方式,还有哪些转码方式, 我现在要一个一个一个的试,没办法,别的配置不能改的呀, help me !!!!!!!!!!!!
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;
public class EncodingFilter implements Filter { protected boolean ignore = true; protected FilterConfig config; protected String targetEncoding = "UTF-8"; public void init(FilterConfig config) throws ServletException { this.config = config;
this.targetEncoding = config.getInitParameter("encoding");
String value = config.getInitParameter("ignore"); if (value == null)
this.ignore = true;
else if (value.equalsIgnoreCase("true"))
this.ignore = true;
else if (value.equalsIgnoreCase("yes"))
this.ignore = true;
else
this.ignore = false;
} public void destroy() {
config = null;
targetEncoding = null;
} public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException { if (ignore ¦ ¦ (request.getCharacterEncoding() == null)) {
String encoding = selectEncoding(request);
if (encoding != null)
request.setCharacterEncoding(encoding);
} chain.doFilter(request, response);
} protected String selectEncoding(ServletRequest request) { return (this.targetEncoding);
}
} 在web.xml 里配置
<filter>
<filter-name>EncodingFilter </filter-name>
<filter-class>cn.usj.gyj.common.EncodingFilter </filter-class>
<init-param>
<param-name>encoding </param-name>
<param-value>UTF-8 </param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>EncodingFilter </filter-name>
<url-pattern>/* </url-pattern>
</filter-mapping>
<Connector port="8080" //你的tomcat端口
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true"/>
在里面加上这个就ok了 useBodyEncodingForURI="true" URIEncoding="UTF-8"
title = new String(title.getBytes("UTF-8"), "GBK");
title = new String(title.getBytes(",。。"), "GBK");