struts项目中文乱码解决方案(java中文乱码解决方案)
来源:互联网 发布:数据资源提供商 编辑:程序博客网 时间:2024/06/11 19:41
关于struts项目,本人有以下解决方案:
jsp 需修改:
<%@ page contentType="text/html;charset=UTF-8" %>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
js 需修改:eclipse 中文件属性的编码设置 :指定 UTF-8
过滤器类设置 :
public class SetCharacterEncodingFilter extends HttpServlet implements Filter ...{
protected String encoding = null;
protected FilterConfig filterConfig = null;
protected boolean ignore = true;
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;
}
}
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) ...{
r eturn (this.encoding);
}
public void destroy() ...{
this.encoding = null;
this.filterConfig = null;
}
}
protected String encoding = null;
protected FilterConfig filterConfig = null;
protected boolean ignore = true;
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;
}
}
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) ...{
r eturn (this.encoding);
}
public void destroy() ...{
this.encoding = null;
this.filterConfig = null;
}
}
配置文件 /WEB-INF/web.xml
<filter>
<filter-name>setcharacterencodingfilter</filter-name>
<filter-class>com.aide.zxdk.servlet.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>setcharacterencodingfilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-name>setcharacterencodingfilter</filter-name>
<filter-class>com.aide.zxdk.servlet.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>setcharacterencodingfilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
- struts项目中文乱码解决方案(java中文乱码解决方案)
- struts中文乱码解决方案
- struts中文乱码解决方案
- struts中文乱码解决方案
- java中文乱码解决方案
- java中文乱码解决方案
- Java 中文乱码解决方案汇总
- java中文乱码及解决方案
- java中文乱码-经典解决方案
- Java操作:中文乱码解决方案
- java中文乱码完全解决方案
- java中文参数乱码解决方案
- Struts中Jsp中文乱码解决方案
- JSP,STRUTS等的中文乱码解决方案
- Struts实现文件下载中文乱码解决方案
- Struts实现文件下载中文乱码解决方案
- struts+hibernate+MySql中文乱码解决方案
- JSP,STRUTS等的中文乱码解决方案
- 解决eclipse resource........4415 question
- 一个很好的效果,隐藏表格
- C#修改app.config配置文件信息
- dingming asterisk 单E1 在zaptel-1.2.22.tar.gz下修改的代码
- applicationContext.xml说明
- struts项目中文乱码解决方案(java中文乱码解决方案)
- aaaaaaaaaaaaaaaaaaaaaaaa
- XML Spy 2007企业版联机验证的解决办法
- Hibernate集合排序之内存排序
- javascript实现从Excel文件向Web表单的某列多行数据复制
- Hibernate包的作用介绍
- ARM程序由于字节对齐引起的问题深入分析
- 《Hibernate开发及整合大全》一书中的一点小错误
- 主从表XtarGrid设计