问题
I'm a french so I put some é è ê ô û in my code. (and I don't speek english very well).
I've a method like that in a class Formulaires
:
public static Formulaire exposé()
And in a config spring xml file, I try :
<entry
key="intro"
value="#{T(com.myproject.Formulaires).exposé()}"/>
But Spring says :
Caused by: java.lang.IllegalStateException: Cannot handle (233) 'é'
at org.springframework.expression.spel.standard.Tokenizer.process(Tokenizer.java:193)
at org.springframework.expression.spel.standard.Tokenizer.<init>(Tokenizer.java:47)
at org.springframework.expression.spel.standard.InternalSpelExpressionParser.doParseExpression(InternalSpelExpressionParser.java:110)
at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:56)
at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:1)
at org.springframework.expression.common.TemplateAwareExpressionParser.parseExpressions(TemplateAwareExpressionParser.java:128)
at org.springframework.expression.common.TemplateAwareExpressionParser.parseTemplate(TemplateAwareExpressionParser.java:74)
at org.springframework.expression.common.TemplateAwareExpressionParser.parseExpression(TemplateAwareExpressionParser.java:64)
at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:119)
... 47 more
If I put e and not é all is good.
Is there some SpEL limit about accents ?
I use spring 3.0.5.
Thanks.
回答1:
Accented characters do not exist in a basic UTF-8 character encoding and the Spring XML files probably use that. As the error says, the parser can't handle accented characters.
There's nothing that you can do to easily solve this problem. Accented characters will give problems in other areas of programming too. I think it would be best to prevent using them.
回答2:
Here's more to it . The code below in Tokenizer decides if it's an alphabetic character
private boolean isAlphabetic(char ch) {
if (ch>255) {
return false;
}
return (flags[ch] & IS_ALPHA)!=0;
}
Your character é is <=255 but the flags[ch] is initialized by the static block below
static {
for (int ch='0';ch<='9';ch++) {
flags[ch]|=IS_DIGIT | IS_HEXDIGIT;
}
for (int ch='A';ch<='F';ch++) {
flags[ch]|= IS_HEXDIGIT;
}
for (int ch='a';ch<='f';ch++) {
flags[ch]|= IS_HEXDIGIT;
}
for (int ch='A';ch<='Z';ch++) {
flags[ch]|= IS_ALPHA;
}
for (int ch='a';ch<='z';ch++) {
flags[ch]|= IS_ALPHA;
}
Hence only a-z or A-Z can be considered ..
来源:https://stackoverflow.com/questions/8571992/spel-cannot-handle-%c3%a9