2013-03-03 25 views
0

我建立使用Spring MVC的3.1罐子一個項目,配置的i18n文件夾後,Tomcat是扔我下面的異常發現消息.apache.jasper.JasperException:javax.servlet.ServletException:javax.servlet.jsp.JspTagException:代碼爲的'label.title'未找到針對語言環境'en_US'的消息。Spring MVC的國際化<春天:消息>給JasperException:</p> <p>組織:沒有下代碼

我曾嘗試添加I18N文件夾中的蝕(朱諾)類路徑,置於消息*下WEB-INF .properties文件/ I18N,WEB-INF /類/ I18N,WEB-INF /類,網頁INF/lib,WEB-INF /但沒有用。

彈簧的context.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans:beans xmlns="http://www.springframework.org/schema/mvc" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans" 
    xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd 
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.1.xsd"> 
    <annotation-driven /> 
    <resources location="/, classpath:/META-INF/web-resources/" 
     mapping="/resources/**" /> 
    <default-servlet-handler /> 
    <beans:bean 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <beans:property name="prefix" value="/WEB-INF/views/" /> 
     <beans:property name="suffix" value=".jsp" /> 
    </beans:bean> 
    <context:component-scan base-package="com.hoe.spring.controller" /> 
    <interceptors> 
     <beans:bean 
      class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" 
      p:paramName="lang" /> 

    </interceptors> 
    <beans:bean 
     class="org.springframework.context.support.ReloadableResourceBundleMessageSource" 
     id="messageSource" p:basenames="WEB-INF/i18n/messages, WEB-INF/i18n/application" 
     p:fallbackToSystemLocale="false" p:fileEncodings="UTF-8" 
    p:defaultEncoding="UTF-8" /> 
    <beans:bean class="org.springframework.web.servlet.i18n.CookieLocaleResolver" 
     id="localeResolver" p:cookieName="locale" /> 
</beans:beans> 

messages.properties

label.title=Contact_Manager 
label.firstname=First_Name 
label.lastname=Last_Name 
label.email=Email 
label.telephone=Telephone 

page.jsp

<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%> 
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%> 
<spring:message code=**"label.title"** var="cName"/> 


label.addcontact=Add_Contact 
label.menu=Menu 

上午什麼我錯過了?提前致謝。

回答

1

我已經劃歸資源/ i18n的文件夾中的文件。

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 
    <property name="basename" value="classpath:i18n/messages" /> 
    <property name="defaultEncoding" value="UTF-8" /> 

0

嘗試將文件放在日蝕的resources/i18n文件夾下,然後使用p:basenames="classpath:i18n/messages"

+0

我已經嘗試了所有上述解決方案,但徒勞無功,沒有一個工作。 – kiran20v 2013-03-16 08:15:59

+0

請發佈最新的細節,如tomcat服務器下屬性文件的實際路徑,屬性文件名和更新後的應用程序上下文xml文件。 – Mamun 2013-03-17 11:29:29

0
<bean id="messageSource"  class="org.springframework.context.support.ResourceBundleMessageSource"> 
    <property name="basenames"> 
         <list> 
           <value>locale.messages</value> 
           <value>locale.validation.messages</value> 
           <value>locale.email.messages</value> 
         </list> 
    </property> 
    </bean> 

並把語言環境文件夾下的屬性文件(相同的封裝結構) 如果是行家/ gradle這個項目的區域設置文件夾來資源文件夾 locale.validation.message =>區域設置/確認/ messages_en_US下。性能

+0

<豆:豆類= 「org.springframework.context.support.ReloadableResourceBundleMessageSource」 \t \t ID = 「爲messageSource」 P:基本名稱= 「locale.messages,locale.validation.messages,locale.email.messages」 – kiran20v 2013-03-04 17:07:10

+0

放置messages_en_US .properties文件在WEB-INF/classes/locale/validations/messages目錄下。獲取相同的錯誤。 – kiran20v 2013-03-04 17:50:39

0

你可以嘗試將message.properties文件名更改爲messages_en_US.properties

+0

我有這個文件(messages_en_US.properties,messages_en_IN.properties,messages.properties,application_en_US.properties,application。屬性)也在文件夾WEB-INF/i18n/ – kiran20v 2013-03-04 07:54:41

+0

下試過了我上面指定的方法。那個正在爲我工​​作 – Mayuran 2013-03-04 08:09:21

+0

是的,我已經嘗試過你的選擇,但我得到同樣的錯誤。我感覺它是一個類路徑問題,在這裏我從eclipse IDE運行tomcat服務器。我已經在eclipse中手動設置classpath(到消息文件夾)。我還需要做更多的事嗎? – kiran20v 2013-03-05 04:52:11

0

我掙扎着同樣的問題,我意識到的是,消息_ {}。屬性必須在類路徑中。所以,你不需要提及basename屬性值「classpath:messages」。而只需提及「消息」。這是我的完整配置。

<bean id="messageSource" 
     class="org.springframework.context.support.ResourceBundleMessageSource"> 
     <property name="basename" value="messages"/> 
     <property name="useCodeAsDefaultMessage" value="true"/> 
     <property name="defaultEncoding" value="UTF-8" />  
</bean> 


<!-- allow localization through cookie and add interceptor to allow changes to locale --> 

<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver" /> 

<mvc:interceptors> 
    <bean id="localeChangeInterceptor" 
      class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"> 
    <property name="paramName" value="lang"/>  
    </bean>   
</mvc:interceptors> 
相關問題