我開發的Spring MVC應用程序,它應該支持英語&阿拉伯語。我已經按照春季參考文檔中提到的配置了應用程序,並且區域設置切換正常。然而,資源包中的阿拉伯語消息顯示爲垃圾字符。編碼設置爲UTF-8,並且工作正常。我也試過了messages_ar.properties文件轉換爲Unicode運行native2ascii工具。Spring MVC的阿拉伯語
沒有用。任何幫助將非常感激。
web.xml中(部分)
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<web-app version="2.4"...>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:META-INF/spring/applicationContext*.xml</param-value>
</context-param>
<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>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Handles all requests into the application -->
<servlet>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/mvc-config.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
MVC-config.xml的(局部的)
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<context:component-scan base-package="net.omnsoq.classified.controller" use-default-filters="false">
<context:include-filter expression="org.springframework.stereotype.Controller" type="annotation" />
</context:component-scan>
<!-- Configures support for @Controllers -->
<mvc:annotation-driven />
<!-- Resolves view names to protected .jsp resources within the /WEB-INF/views directory -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource" id="messageSource"
p:basenames="WEB-INF/i18n/messages,WEB-INF/i18n/application" p:fallbackToSystemLocale="false" />
<!-- store preferred language configuration in a cookie -->
<bean class="org.springframework.web.servlet.i18n.CookieLocaleResolver" id="localeResolver" p:cookieName="locale" />
<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" p:paramName="lang" />
</mvc:interceptors>
JSP代碼
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
...
<%@page contentType="text/html;charset=UTF-8" %>
...
<spring:message code="nav.label.myaccount" />
我最初嘗試了這一點,令我驚訝的是它沒有奏效。那真正的頭疼開始了。 – 2010-06-11 17:00:27
是的,你的解決方案也正在與 –
2010-06-11 17:02:42