当前位置: 代码迷 >> Eclipse >> Eclipse rcp/rap 开发经验总结(8) - 发布到tomcat后解决rap编码和字符集的有关问题
  详细解决方案

Eclipse rcp/rap 开发经验总结(8) - 发布到tomcat后解决rap编码和字符集的有关问题

热度:271   发布时间:2016-04-23 12:40:25.0
Eclipse rcp/rap 开发经验总结(8) - 发布到tomcat后解决rap编码和字符集的问题

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

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

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


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

??? 使用传统的 字符集过滤器


??? 写一个过滤器类

?

?

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;  }}

?

?

?

?

?

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

web.xml添加

?

?

?

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

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


?

内容如下


?

  <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>

?

?

?

2.增加jar

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

?

?

?

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

?
  相关解决方案