zoukankan      html  css  js  c++  java
  • Eclipse rap 富客户端开发总结(8) : 发布到tomcat后解决rap编码和字符集的问题

    1 、解决 rap 字符集乱码的问题

        字符集问题,解决办法:   在plugin.xml - build.properties 中添加

          javacDefaultEncoding.. = UTF-8   即可解决字符集乱码

    2、解决web前台输入乱码问题

        使用传统的 字符集过滤器

        写一个过滤器类

    [java] view plain copy
     
     print?
    1. <span style="font-size: small;">public class CharacterEncodingFilter implements Filter  
    2. {  
    3.   private String edcoding;  
    4.   
    5.   private FilterConfig filterConfig;  
    6.   
    7.   private boolean ignore;  
    8.   
    9.   public CharacterEncodingFilter()  
    10.   
    11.   {  
    12.     this.edcoding = null;  
    13.   
    14.     this.filterConfig = null;  
    15.   
    16.     this.ignore = true; }  
    17.   public void destroy() {  
    18.   
    19.     this.edcoding = null;  
    20.   
    21.     this.filterConfig = null;  
    22.   
    23.   }  
    24.   
    25.   public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException  
    26.   
    27.   {  
    28.   
    29.     if ((this.ignore) || (request.getCharacterEncoding() == null)) {  
    30.   
    31.       String encoding = setCharacterEncoding(request);  
    32.       if (encoding != null)  
    33.   
    34.         request.setCharacterEncoding(encoding)  
    35.   
    36.     }  
    37.   
    38.   
    39.     filterChain.doFilter(request, response);  
    40.   
    41.   }  
    42.   
    43.   
    44.   
    45.   public void init(FilterConfig filterConfig) throws ServletException {  
    46.     this.filterConfig = filterConfig;  
    47.     this.edcoding = filterConfig.getInitParameter("encoding");  
    48.     String value = filterConfig.getInitParameter("ignore");  
    49.   
    50.     if (value == null)  
    51.       this.ignore = true;  
    52.     else if (value.equalsIgnoreCase("true")) {  
    53.       this.ignore = true;  
    54.     }  
    55.     else  
    56.       this.ignore = false;  
    57.   }  
    58.   public String setCharacterEncoding(ServletRequest request)  
    59.   
    60.   {  
    61.   
    62.     return this.edcoding;  
    63.   
    64.   }  
    65.   
    66. }  
    67.   
    68. </span>  

    然后达成 jar 包方式到 war /WEB_INF/lib 目录下面

    在 web.xml 添加rap 导出 war 包时,编码问题处理,加入了字符过滤器的处理方式

    1. 在导出 WAR 后,修改 war 包里面的 web.xml 文件,添加过滤器

    内容如下

    [html] view plain copy
     
     print?
    1. <span style="font-size: small;"><span>  <filter>    
    2.   
    3.         <filter-name>CharacterEncodingFilter</filter-name>    
    4.   
    5.         <filter-class>com.encoding.CharacterEncodingFilter</filter-class>    
    6.   
    7.         <init-param>    
    8.   
    9.             <param-name>encoding</param-name>    
    10.   
    11.             <param-value>UTF-8</param-value>    
    12.   
    13.         </init-param>    
    14.   
    15.     </filter>    
    16.   
    17.     <filter-mapping>    
    18.   
    19.         <filter-name>CharacterEncodingFilter</filter-name>    
    20.   
    21.         <url-pattern>/*</url-pattern>    
    22.   
    23. </filter-mapping>  
    24.   
    25. </span>  
    26.   
    27. </span

    2. 增加 jar 包

       把过滤器要用的 jar 包【 encoding.jar 】添加到导出的 WAR 包的 lib 下面,这样     WAR 包加载后,能够找寻到过滤器用到的类。上面 2 部分可以保证完美的解决中文问题

  • 相关阅读:
    [BZOJ 2144]跳跳棋
    [NOIp 2015]信息传递
    [JLOI 2014]松鼠的新家
    [Luogu 2062]分队问题
    [Luogu 2090]数字对
    [NOIp 2015]运输计划
    [USACO 03FEB]Farm Tour
    [TJOI 2010]中位数
    IO密集型 计算密集型
    python 编码
  • 原文地址:https://www.cnblogs.com/dengyungao/p/7503621.html
Copyright © 2011-2022 走看看