CSDN博客

img DickWinters

Struts中文乱码问题解决

发表于2004/10/19 18:53:00  2648人阅读

分类: Struts

主要方法是加入一个过滤器
web.xml
加入如下内容:
<filter>
    <filter-name>Set Character Encoding</filter-name>
    <filter-class>SetCharacterEncodingFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>Set Character Encoding</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>



SetCharacterEncodingFilter.java

package edu.bit.dick.article;

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 javax.servlet.UnavailableException;

public class SetCharacterEncodingFilter implements Filter
{
 public void init(FilterConfig filterConfig) throws ServletException{}
 public void destroy(){}

 public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException,ServletException
 {
  request.setCharacterEncoding("GB18030");
  //传递控制到下一个过滤器
  chain.doFilter(request,response);
 }
}

阅读全文
0 0

相关文章推荐

img
取 消
img