JAVA代码
- public class EncodeFilter implements Filter {
- @Override
- public void destroy() {
- // TODO Auto-generated method stub
- }
- @Override
- public void doFilter(ServletRequest request, ServletResponse response,
- FilterChain chain) throws IOException, ServletException {
- // TODO Auto-generated method stub
- //从浏览器中的到的二进制数据用utf-8编码
- request.setCharacterEncoding("UTF-8");
- chain.doFilter(request, response);
- }
- @Override
- public void init(FilterConfig arg0) throws ServletException {
- // TODO Auto-generated method stub
- }
- }
XML配置---------------------------------------
- <filter>
- <filter-name>encoding</filter-name>
- <filter-class>cn.itcase.strutsdemo.user.domain.EncodeFilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>encoding</filter-name>
- <servlet-name>action</servlet-name>
- </filter-mapping>