【问题记录】springmvc国际化问题
异常-Cannot change HTTP accept header - use a different locale resolution strategy
springmvc国际化时,locale resolution strategy
的bean命名一定是localeResolver
例如:
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.SessionLocaleResolver" />
中文乱码-解决从properties文件到jsp界面乱码问题
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:i18n/messages" />
<property name="useCodeAsDefaultMessage" value="true" />
<!-- 禁止在生产环境中使用它,开发可用 -->
<property name="cacheSeconds" value="0" />
<!-- 解决从properties文件到jsp界面乱码问题 -->
<property name="defaultEncoding" value="UTF-8"/>
</bean>
中文乱码-解决前端到后台乱码问题
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
注意jsp页面中的编码格式也要设置为UTF-8
哦。