乱码、乱码 jsp向jsp传递中文出现乱码,怎么解决啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 第一步:写个fiter类SetCharacterEncodingFilter.javapackage com.niexiong.fiter;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 SetCharacterEncodingFilter implements Filter{ protected String encoding = "GB2312"; 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 { if (!ignore) { String encoding = selectEncoding(request); request.setCharacterEncoding(encoding); } 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); }}第二步:web.xml中添加 <filter> <filter-name>SetCharacterEncoding</filter-name> <filter-class>com.niexiong.fiter.SetCharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>GBK</param-value> </init-param> <init-param> <param-name>ignore</param-name> <param-value>false</param-value> </init-param> </filter> <filter-mapping> <filter-name>SetCharacterEncoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> 第三步:jsp页面都添加<%@ page contentType="text/html;charset=GBK" %> 在jsp页面加上<% request.setCharacterEncoding("GBK");%>另外保存jsp时,注意转换类型 1楼说的类,编译通不过,出错:软件包javax.servlet不存在,还有很多其他问题,是怎么回事? 没有建web工程。我只是想把中文能够正常显示而已 <%@ page contentType="text/html;charset=gbk"%> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title></title> </head> 有的时候你会发现即使2楼和8楼的方法都用了,还是会出现乱码的.当出现这样的问题的时候,你可以使用这样的方法:<%out.println(new String(temp.getBytes("iso-8859-1")));%>temp就是字符串的变量名. ResultSet的问题 页面提交数据之后的刷新问题。 打扰各位休息了,来帮个忙 不用struts标签如何取得struts国际化资源文件中的值 求救 applet用HTML打开无法显示 一个奇怪的错误请大家帮忙(jsp) 关于标志库中异常的处理,谢谢! 有关用jsp操作数据库中的时间问题(急用)!!!!!!!!!!!!!! Spring boot 的ribbon转发post请求总是失败 我做的网站为什么有几个字显示不出来? 一个数据库更新的问题
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 SetCharacterEncodingFilter implements Filter
{ protected String encoding = "GB2312";
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
{ if (!ignore)
{
String encoding = selectEncoding(request);
request.setCharacterEncoding(encoding);
}
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); }
}第二步:web.xml中添加 <filter>
<filter-name>SetCharacterEncoding</filter-name>
<filter-class>com.niexiong.fiter.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
<init-param>
<param-name>ignore</param-name>
<param-value>false</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>SetCharacterEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
第三步:jsp页面都添加<%@ page contentType="text/html;charset=GBK" %>
<% request.setCharacterEncoding("GBK");%>另外保存jsp时,注意转换类型
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title> </head>
当出现这样的问题的时候,你可以使用这样的方法:
<%out.println(new String(temp.getBytes("iso-8859-1")));%>
temp就是字符串的变量名.