struts1中文乱码

struts1乱码解决方案:

利用过虑器.自己写个 过虑器:
代码如下:

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;

public class CharacterEncodingFilter implements Filter {

public void destroy() {
// TODO Auto-generated method stub

}

public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding("UTF-8");
chain.doFilter(request, response);

}

public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub

}

}

然后在 web.xml中添加过虑器:

在 web.xml前添加如下代码:

<filter>
<filter-name>characterEnconding</filter-name>
<filter-class>过虑器路徑</filter-class>
</filter>
<filter-mapping>
<filter-name>characterEnconding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

你可能感兴趣的:(xml,Web,servlet)