使用filter解决中文乱码问题--struts2乱码
来源:互联网 发布:medline数据库检索 编辑:程序博客网 时间:2024/05/29 04:32
一.在web.xml中配置
xml 代码
<filter> <filter-name>EncodingFilter</filter-name> <filter-class>com.kenshin.base.SysFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>enable</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>EncodingFilter</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping>
二.filter类代码
java 代码
package com.kenshin.base; 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 org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; public class SysFilter implements Filter { protected String sEncodingName; protected FilterConfig sysFilter; protected boolean bEnable; protected Log logger = LogFactory.getLog(SysFilter.class); public void destroy() { } public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException { // TODO Auto-generated method stub if (this.bEnable) { try { arg0.setCharacterEncoding(this.sEncodingName); arg1.setContentType("text/html;charset=" + this.sEncodingName); arg1.setCharacterEncoding(this.sEncodingName); arg2.doFilter(arg0, arg1); } catch (Exception e) { logger.info("出错了"); } // session.close(); } else { arg2.doFilter(arg0, arg1); } } public void init(FilterConfig arg0) throws ServletException { // TODO Auto-generated method stub this.sysFilter = arg0; this.loadFilterSetting(); } private void loadFilterSetting() { this.sEncodingName = this.sysFilter.getInitParameter("encoding"); logger.info("encoding:" + sEncodingName); String sEnable = this.sysFilter.getInitParameter("enable"); if (sEnable != null && sEnable.equalsIgnoreCase("true")) { this.bEnable = true; } else { this.bEnable = false; } } }
- 使用filter解决中文乱码问题--struts2乱码
- 使用Filter解决中文乱码问题
- Filter解决中文乱码问题
- struts2 解决中文乱码问题
- struts2解决中文乱码问题
- struts2解决中文乱码问题
- struts2解决中文乱码问题
- 使用Filter解决乱码问题
- Filter的使用(解决中文乱码问题)
- 使用filter解决get请求中文乱码问题
- javaweb开发中的中文乱码问题,使用Filter过滤器解决
- Tomcat中文乱码问题filter解决
- Filter全局解决中文乱码问题
- Filter 解决全站中文乱码问题
- javaWeb利用Filter解决中文乱码问题
- Filter拦截器解决中文乱码问题
- 使用 Filter 过滤器 处理中文 乱码问题
- struts2解决中文乱码
- 2013-4-9
- [WinForm]写一个小程序把指定目录的程序添加到开机自动启动(无法绕过360检查)
- 想从事DBA工作,该挑选哪一款数据库产品
- 只用一个循环,输出九九乘法表
- 75个移动App开发教程
- 使用filter解决中文乱码问题--struts2乱码
- 370. Reading is to the mind while exercise to the body. 读书健脑,运动健身
- LPC177x/8x勘误手册
- c#解决statusStrip控件上的项目不能靠右对齐的问题
- Android5个进程等级
- vb.net 打开pdf文件
- Ubuntu搭建Eclipse+JDK+SDK的Android
- 三层交换原理及示例详解
- Cocos2d-X内存管理研究<一>