Develop struts to solve garbled problems under Eclipse tools

Source: Internet
Author: User
Tags tomcat

There are three main questions:

1,struts in resource file if value is Chinese, display garbled

Workaround: Use the Eclipse plug-in properties Editor

2, in the text field input Chinese display garbled

Workaround: Use the servlet filter filter

The simplest of these can be borrowed from the filters below Tomcat. Setcharacterencodingfilter in their own web.xml configuration to add Tomcat servlet_examples corresponding configuration (master can be their own match!)

My configuration is as follows:

Setcharacterencoding

Filters. Setcharacterencodingfilter

Encoding

GBK

Setcharacterencoding

*.do

3, read garbled from some database

Solution: Re-encode the part you want to display as Chinese

For example:

while (rs.next())
  {
  String col1 = rs.getString(1);
  String col2 = rs.getString(2);
  String col3 = rs.getString(3);
  float col4 = rs.getFloat(4);
  //convert character encoding
  col1=new String(col1.getBytes("ISO-8859-1"),"GB2312");
  col2=new String(col2.getBytes("ISO-8859-1"),"GB2312");
  col3=new String(col3.getBytes("ISO-8859-1"),"GB2312");
  }

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.