Java Code Filter Emoji emoticons

Source: Internet
Author: User

You can create a new class of filters and write the following code in the class:

public static String filterEmoji(String source) {           if(source != null)         {             Pattern emoji = Pattern.compile ("[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]",Pattern.UNICODE_CASE | Pattern . CASE_INSENSITIVE ) ;             Matcher emojiMatcher = emoji.matcher(source);             if ( emojiMatcher.find())              {                 source = emojiMatcher.replaceAll("*");                 return source ;              }         return source;        }        return source;       }If there is no change, you can write the following code in the class: private static final long serialversionuid = -5916500037685553487l;
public void Destroy () {
TODO auto-generated Method Stub
}

@SuppressWarnings ("Unchecked")
public void DoFilter (ServletRequest request, servletresponse response,
Filterchain arg2) throws IOException, Servletexception {
HttpServletRequest ServletRequest = (httpservletrequest) request;
New Plus Code http://www.2cto.com/kf/201512/455191.html
HttpServletResponse servletresponse = (httpservletresponse) response;
String param = "";
String paramvalue = "";

Servletresponse.setcontenttype ("text/html");
Servletresponse.setcharacterencoding ("UTF-8");
Servletrequest.setcharacterencoding ("UTF-8");
Java.util.Enumeration params = Request.getparameternames ();
while (Params.hasmoreelements ()) {

param = (String) params.nextelement ();
String[] values = servletrequest.getparametervalues (param);//Get the value of each parameter

for (int i = 0; i < values.length; i++) {

Paramvalue = Values[i];


Paramvalue = Paramvalue.replaceall ("<script>", "(*");
Paramvalue = Paramvalue.replaceall ("</script>", ")");
Paramvalue = Paramvalue.replaceall ("[\ud83c\udc00-\ud83c\udfff]|[ \ud83d\udc00-\ud83d\udfff]| [\U2600-\U27FF] "," "); Filter Emoji Emoticons


This can also be increased, as leaders automatically escape into * * *, can read illegal keywords from the database.
Values[i] = paramvalue;
}

Re-return the escaped parameters back to request
Request.setattribute (param, paramvalue);
}
Continue down

Arg2.dofilter (request, response);

}

public void init (Filterconfig arg0) throws Servletexception {
Initialization

}
}

Java Code Filter Emoji emoticons

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.