Eclipse rap 富客户端开发总结(8) - 发布到tomcat后解决rap编码和字符集的问题

注: Eclipse rap 富客户端开发总结-系列文章是从本人   Iteye博客中移植过来.后续会直接在此更新     http://jlins.iteye.com/

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

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

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

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

    使用传统的 字符集过滤器

    写一个过滤器类

<span style="font-size: small;">public class CharacterEncodingFilter implements Filter
{
  private String edcoding;

  private FilterConfig filterConfig;

  private boolean ignore;

  public CharacterEncodingFilter()

  {
    this.edcoding = null;

    this.filterConfig = null;

    this.ignore = true; }
  public void destroy() {

    this.edcoding = null;

    this.filterConfig = null;

  }

  public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException

  {

    if ((this.ignore) || (request.getCharacterEncoding() == null)) {

      String encoding = setCharacterEncoding(request);
      if (encoding != null)

        request.setCharacterEncoding(encoding)

    }


    filterChain.doFilter(request, response);

  }



  public void init(FilterConfig filterConfig) throws ServletException {
    this.filterConfig = filterConfig;
    this.edcoding = filterConfig.getInitParameter("encoding");
    String value = filterConfig.getInitParameter("ignore");

    if (value == null)
      this.ignore = true;
    else if (value.equalsIgnoreCase("true")) {
      this.ignore = true;
    }
    else
      this.ignore = false;
  }
  public String setCharacterEncoding(ServletRequest request)

  {

    return this.edcoding;

  }

}

</span>


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

在 web.xml 添加

 

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

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

内容如下

<span style="font-size: small;"><span>  <filter>  

        <filter-name>CharacterEncodingFilter</filter-name>  

        <filter-class>com.encoding.CharacterEncodingFilter</filter-class>  

        <init-param>  

            <param-name>encoding</param-name>  

            <param-value>UTF-8</param-value>  

        </init-param>  

    </filter>  

    <filter-mapping>  

        <filter-name>CharacterEncodingFilter</filter-name>  

        <url-pattern>/*</url-pattern>  

</filter-mapping>

</span>

</span>


2. 增加 jar 包

   把过滤器要用的 jar 包【 encoding.jar 】添加到导出的 WAR 包的 lib 下面,这样     WAR 包加载后,能够找寻到过滤器用到的类。

 

上面 2 部分可以保证完美的解决中文问题


<script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值