Struts页面乱码

过滤器

public class MyFilter extends HttpServlet implements Filter {

 @Override  public void doFilter(ServletRequest arg0, ServletResponse arg1,    FilterChain arg2) throws IOException, ServletException {   

          arg0.setCharacterEncoding("utf-8"); //设置接收编码   

    arg1.setContentType("text/html;charset=utf-8");     

          arg2.doFilter(arg0, arg1);   //必须

 }

 

Web.XML

  <!-- 过滤器 -->
  <filter>
    <filter-name>MyFilter</filter-name>
     <filter-class>cn.yct.servlet.MyFilter</filter-class>    包名
  </filter>
  <filter-mapping>
    <filter-name>MyFilter</filter-name>
     <url-pattern>/*</url-pattern>
   </filter-mapping>

posted on   —颜翠婷—  阅读(137)  评论(0编辑  收藏  举报

< 2025年1月 >
29 30 31 1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31 1
2 3 4 5 6 7 8

导航

统计

点击右上角即可分享
微信分享提示