myeclipse jsp post方式提交中文乱码解决办法
2012-05-30 18:40
615 查看
import java.io.*; 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 = null; public void destroy() { this.encoding = null; } public void init(FilterConfig filterConfig) throws ServletException { this.encoding = filterConfig.getInitParameter("encoding"); } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { request.setCharacterEncoding(encoding); response.setContentType("text/html;charset=" + encoding); chain.doFilter(request, response); } }
web.xml配置如下:
<filter> <filter-name>SetCharacterEncodingFilter</filter-name> <filter-class> com.smzbtv.filter.SetCharacterEncodingFilter </filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>SetCharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>注意: 以上web.xml里对转码的配置必须放在Struts2配置前面
相关文章推荐
- myeclipse jsp post方式提交中文乱码解决办法
- myeclipse jsp post方式提交中文乱码解决办法
- JSP中,AJAX使用POST方式提交中文乱码问题解决
- jsp中Get提交方式的中文乱码解决办法
- JSP中,AJAX使用POST方式提交中文乱码问题解决
- jsp中Get提交方式的中文乱码解决办法
- jsp中Get提交方式的中文乱码解决办法
- jsp中Get提交方式的中文乱码解决办法
- jsp中Get提交方式的中文乱码解决办法
- Android以post方式传输中文出现乱码解决办法
- 中文乱码问题解决,过滤器配置,get post提交乱码,filter,struts乱码,jsp乱码
- 关于jsp中文提交到后台乱码问题解决办法
- JQuery中Ajax的Post提交中文乱码、windows.location.href 中文汉字乱码和springmvc使用原生态HttpServletRequest接收参数中文乱码解决办法
- jsp页面利用get方式提交到后台的数据为乱码格式的解决办法
- JSP中解决中文乱码问题 对于post有效 对于get请求方式无效。
- HTML使用post方式提交中文内容出现乱码的错误解决方式
- 解决中文乱码的filter(包括get和post提交两种方式)
- Tomcat get/post提交中文乱码解决办法
- 采用DoGet方式提交中文,乱码产生原因分析及解决办法
- JSP解决ajax使用$.get()方式提交中文出现乱码问题