Eclipse rap rich client Development Summary (8)-release to Tomcat solves the problems of rap encoding and Character Set

Source: Internet
Author: User
Note: Eclipse rap rich client Development Summary-a series of articles are transplanted from my iteye blog. Later will directly update the http://jlins.iteye.com/

1. solve the issue of garbled rap character sets

Character Set Problem, solution: Add in plugin. XML-build. Properties

Javacdefaultencoding .. = UTF-8 to solve Character Set garbled

2. Solve the Problem of garbled Web Front-end input

Use traditional character set Filters

Write a filter class

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

Then the jar package method is reached under the war/web_inf/lib directory.

Add in Web. xml

 

When rap exports a war package, encoding problems are handled. The character filter processing method is added.

1. After exporting the war, modify the Web. xml file in the war package and add a filter.

The content is as follows:

<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. Add a jar package

Add the jar package [encoding. jar] used by the filter to the Lib of the exported war package. After the war package is loaded, you can find the classes used by the filter.

 

The above two parts can perfectly solve Chinese problems

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.