加上
<%@page contentType="text/html;charset=gb2312"%>----簡體
<%@page contentType="text/html;charset=Big5"%>----繁體
<%@page contentType="text/html;charset=GBK"%>----簡繁體
<%@page contentType="text/html;charset=gb2312"%>----簡體
<%@page contentType="text/html;charset=Big5"%>----繁體
<%@page contentType="text/html;charset=GBK"%>----簡繁體
解决方案 »
- java.lang.IllegalStateException: Cannot forward a response that is already commi
- 求助有关img标签的问题,急!谢谢
- 写好的bean应该保存到哪??
- 一道数学题:排列组合,ABCD按照不同的顺序有多少种排列,分别列出来,用JSP。
- 怎么给javabean里边的变量赋值?
- 提一个简单的问题,怎样让我的jsp页面在键盘按下后执行提交按钮的功能(页面上已经有一个提交按钮,提交一个form)
- JEJ
- 为什么我的JSP文件运行后中文会是乱码?
- 关于JDBC 的下载问题.
- 用jbuilder5.0与weblogic6.0开发jsp的问题
- 为什么这样
- 我现在有一网站,用的是JSP+MYSQL现在要转为JSP+MSSQL,怎么转?谢谢各位了!
import java.io.IOException;
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 {
if (ignore || (request.getCharacterEncoding() == null)) {
String encoding = selectEncoding(request);
if (encoding != null)
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-app>中<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>*.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value> //多换几个编码方式试试
</init-param>
<init-param>
<param-name>ignore</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
试一下这样看行不
=================
public static String toUnicode(String sGb) {
if (sGb == null) {
return null;
}
if (sGb.trim().length() == 0) {
return sGb;
} String sUnicode = "";
try {
sUnicode = new String(sGb.getBytes("ISO-8859-1"), "GB2312");
}
catch (Exception e) {
return "";
}
return sUnicode;
}
用的时候调用toUnicode()就行了