上周更新了一下myblog,添加了一个Filter,做统计访问用。可是后来发现出现乱码问题了。找了很久都没有找到问题。debug的时候看到 CharacterEncodingFilter确实是执行了。不过就是没有效果。执行之前是ISO-8859-1编码的,执行之后还是, CharacterEncodingFilter就没有起到作用。后来终于找到问题的原因了。原来是Filter配置先后顺序的原因。
刚开始的配置是这样的:
<
filter-mapping
>
< filter-name > requestCounterFilter </ filter-name >
< url-pattern > *.jhtml </ url-pattern >
</ filter-mapping >
< filter-mapping >
< filter-name > encodingFilter </ filter-name >
< url-pattern > /dwr/* </ url-pattern >
</ filter-mapping >
< filter-mapping >
< filter-name > encodingFilter </ filter-name >
< url-pattern > *.jhtml </ url-pattern >
</ filter-mapping >
< filter-mapping >
< filter-name > encodingFilter </ filter-name >
< url-pattern > *.jsp </ url-pattern >
</ filter-mapping >
< filter-name > requestCounterFilter </ filter-name >
< url-pattern > *.jhtml </ url-pattern >
</ filter-mapping >
< filter-mapping >
< filter-name > encodingFilter </ filter-name >
< url-pattern > /dwr/* </ url-pattern >
</ filter-mapping >
< filter-mapping >
< filter-name > encodingFilter </ filter-name >
< url-pattern > *.jhtml </ url-pattern >
</ filter-mapping >
< filter-mapping >
< filter-name > encodingFilter </ filter-name >
< url-pattern > *.jsp </ url-pattern >
</ filter-mapping >
先经过那个统计的filter然后再经过编码的filter。这样的话编码的filter就不起作用了。只要吧编码的filter放到最前面就没有问题了。改成这样就好。
<
filter-mapping
>
< filter-name > encodingFilter </ filter-name >
< url-pattern > /dwr/* </ url-pattern >
</ filter-mapping >
< filter-mapping >
< filter-name > encodingFilter </ filter-name >
< url-pattern > *.jhtml </ url-pattern >
</ filter-mapping >
< filter-mapping >
< filter-name > encodingFilter </ filter-name >
< url-pattern > *.jsp </ url-pattern >
</ filter-mapping >
< filter-mapping >
< filter-name > requestCounterFilter </ filter-name >
< url-pattern > *.jhtml </ url-pattern >
</ filter-mapping >
< filter-name > encodingFilter </ filter-name >
< url-pattern > /dwr/* </ url-pattern >
</ filter-mapping >
< filter-mapping >
< filter-name > encodingFilter </ filter-name >
< url-pattern > *.jhtml </ url-pattern >
</ filter-mapping >
< filter-mapping >
< filter-name > encodingFilter </ filter-name >
< url-pattern > *.jsp </ url-pattern >
</ filter-mapping >
< filter-mapping >
< filter-name > requestCounterFilter </ filter-name >
< url-pattern > *.jhtml </ url-pattern >
</ filter-mapping >
以后大家一定要注意啊。顺序问题也是很重要的。
除经特别注明外,本文章版权归莫多泡泡所有.
署名,非商业用途,保持一致. somebody(莫多)