Joke Collection Website - Blessing messages - How to deal with Chinese garbled code in java development?

How to deal with Chinese garbled code in java development?

To deal with garbled code, you need to write a filter, that is, create a new class and implement the javax.servlet.Filter class. In the doFilter method of this class, write:

arg 0 . setcharacterencoding(" utf-8 ");

arg 1 . setcharacterencoding(" utf-8 ");

arg2.doFilter(arg0,arg 1);

Then configure the filter in web.xml

& lt filter & gt

& lt filter name & gtchinesefilter & lt/filter-name >

& ltfilter-class & gt; com . filter . chinesefilter & lt; /filter-class & gt;

& lt/filter & gt;

& lt filter mapping & gt

& lt filter name & gtchinesefilter & lt/filter-name >

& lturl mode & gt/* & lt;; /URL-pattern & gt;

& lt/filter-mapping & gt;

In the above configuration code, ChineseFilter is the name of the newly created filter class, com.filter.ChineseFilter means that my ChineseFilter.java is put in the com.filter package, and/* means that the filter will handle everything in this project.

It's hard to make it clear in a few words.