乱码问题 有谁能把这段乱码转化为中文,"鍚戝鐢熶粙缁峎indows XP鐨勫熀鏈敼杩涙儏鍐点?" 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果你用的是JSP的话,你在头中加入“gb2312”应该就可以了吧?? String notice = new String(request.getParameter("notice").getBytes( "ISO8859_1"), "gb2312"); "鍚戝鐢熶粙缁峎indows XP鐨勫熀鏈敼杩涙儏鍐点?不能完全翻译,我也是在写入的时候翻译的 加一个过滤器web.xml: <filter> <filter-name>CharacterEncodingFilter</filter-name> <display-name>编码过滤器</display-name> <description>解决中文问题。</description> <filter-class>com.xxx.SetCharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>GBK</param-value> </init-param> </filter> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <servlet-name>action</servlet-name> </filter-mapping> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping>SetCharacterEncodingFilter.class: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;public class SetCharacterEncodingFilter implements Filter { protected String encoding = null; protected FilterConfig filterConfig = null; protected boolean ignore = true; public void destroy() { this.encoding = null; this.filterConfig = null; } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // Conditionally select and set the character encoding to be used if (ignore || (request.getCharacterEncoding() == null)) { String encoding = selectEncoding(request); if (encoding != null) { request.setCharacterEncoding(encoding); } } // Pass control on to the next filter chain.doFilter(request, response); } public void init(FilterConfig filterConfig) throws ServletException { this.filterConfig = filterConfig; this.encoding = filterConfig.getInitParameter("encoding"); String value = filterConfig.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; } } protected String selectEncoding(ServletRequest request) { return (this.encoding); }} string aaa=new String(string1.getBytes("iso8859_1"),"gb2312");}catch(Exception e){}因为好多时候在传送时都会让系统自己转编码,所以只有读取的时候转了就无问题了.试试上面的代码吧,如果不行就再把db2312换个gbk试一下. rmi 超时的问题 win7跟vista那些系统桌面右边的小工具怎么做? servlet配置(网站前后台) 怎么获取上传图片的路径 weblogic下部署web应用的url问题 <html:select>对应数据库数据的问题 jsp+xml怎么在B/S的模式下实现树型目录(如windows的资源管理器) 大家帮我看看这个struts页面哪里有问题啊? 请问如何用java调用windows命令行命令? JBuilder + WebSphere(WebLogic)开发EJB的资料 谁做过在java里通过代理访问webservice服务么? 各位java大哥,关于读取XML文件,怎么做啊?
"ISO8859_1"), "gb2312");
web.xml:
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<display-name>编码过滤器</display-name>
<description>解决中文问题。</description>
<filter-class>com.xxx.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<servlet-name>action</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
SetCharacterEncodingFilter.class: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;public class SetCharacterEncodingFilter
implements Filter { protected String encoding = null;
protected FilterConfig filterConfig = null;
protected boolean ignore = true;
public void destroy() { this.encoding = null;
this.filterConfig = null; }
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
// Conditionally select and set the character encoding to be used
if (ignore || (request.getCharacterEncoding() == null)) {
String encoding = selectEncoding(request);
if (encoding != null) {
request.setCharacterEncoding(encoding);
}
} // Pass control on to the next filter
chain.doFilter(request, response); }
public void init(FilterConfig filterConfig) throws ServletException { this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
String value = filterConfig.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;
} }
protected String selectEncoding(ServletRequest request) { return (this.encoding); }}
因为好多时候在传送时都会让系统自己转编码,所以只有读取的时候转了就无问题了.试试上面的代码吧,如果不行就再把db2312换个gbk试一下.