怎么在servlet中判断jsp页面提交的请求中的值是中文?
1个回答
2014-03-26
展开全部
朋友,我来告诉你答案!获得到请求中的字符之后转换成字符数组调用如下方法
privatebooleanisChinese(charc){
Character.UnicodeBlockub=Character.UnicodeBlock.of(c);
if(ub==Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
||ub==Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
||ub==Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
||ub==Character.UnicodeBlock.GENERAL_PUNCTUATION
||ub==Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
||ub==Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS){
returntrue;
}
returnfalse;
}
不过还是建议使用正则
privatebooleanisChinese(charc){
Character.UnicodeBlockub=Character.UnicodeBlock.of(c);
if(ub==Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
||ub==Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
||ub==Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
||ub==Character.UnicodeBlock.GENERAL_PUNCTUATION
||ub==Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
||ub==Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS){
returntrue;
}
returnfalse;
}
不过还是建议使用正则
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询