2016-06-18 16 views
2

1つのWebアプリケーションを作成しています。このアプリケーションでは、私はmaven,Spring framework,Hibernate framework,JSP,Apache tilesを使用しています。JSPプロパティファイルの読み取り

まだこのアプリケーションは英語です。だから私の要件は変換アプリケーションはポルトガル語である。だから私はポルトガル語のための1つのプロパティファイルを作成し、必要なときにこのプロパティファイルを使用します。私は正常に動作し、その時点でmessages.propertiesファイルから値をフェッチ私のJSPページ内のポルトガル語(messages_pt.properties

ための英語(messages.properties)、2のための2つのプロパティ・ファイルを作成私のアプリケーションで


1が、その時点でmessages_pt.propertieのファイルから取り出すときmessages_pt.propertiesファイルに

が見るいくつかの特殊文字が含まれているため、正常に動作していない私の両方のプロパティファイル

messages.properties 
    gas=Gas 

messages_pt.properties 
    gas=Gás 

は今私のJSPページがこの

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
     .............. 
    </head> 
    <body> 
     .............. 
     <fmt:message key="gas" /> 
    </body> 
</html> 

ためそうフェッチ値のようなものです プロパティファイルからキーによって私が読ん値のためfmt tag libraryを使用しています...私の質問にJSPページで

来ますgasキーからmessages_pt.propertiesファイルを取得すると、G�sという値になります。

私はグーグルでソリューションを検索し、いくつかの解決策を得ることなく、誰もが、私はJSPページでは)ソリューション

1未満に適用しています私の問題

を解決することはできません私は、最初の行には、メタタグでのcontentTypeを追加します。上記の私のJSPページをご覧ください。

2)CharacterEncodingFilterweb.xmlファイルに追加しました。このフィルタは最初のフィルタの先頭ページにあります。

<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> 

3)は私はpom.xmlファイルにproject.build.sourceEncodingを添加

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 
     <property name="basenames"> 
      <list> 
       <value>classpath:properties/messages</value> 
      </list> 
     </property> 
     <property name="defaultEncoding" value="UTF-8"/> 
     <property name="useCodeAsDefaultMessage" value="true"/> 
    </bean> 

4)xxx-servlet.xmlファイルにmessageSourceBeandefaultEncodingを添加しました。

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    ....... 
</properties> 

5)私は

コードの下
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%> 
<p><spring:message code="label.menu"/></p> 

を試してみました。しかし、今私の問題を解決することができます。

誰かが他の解決策を知っていたら、教えてください。

+0

プロパティファイルはISO-8859-1でエンコードされています。私の推測では、あなたのものはUTF8でエンコードされています。 –

+0

返信のためのJBありがとう..私は 'ISO-8859-1'でエンコードされたプロパティファイルを試しましたが、 'Gás'の代わりに 'G�s'を取得しました。だからあなたは他のソリューションを持っていますか? –

答えて

2

私は過去に同じ問題を抱えていました。次の解決方法は、添付のスクリーンショットを参照してください。

enter image description here

ゴー性質を提出する>リソース>

変更yourcコンテンツタイプUTF-8へ。

+0

ありがとうparth ..あなたは私の時間を節約... –

関連する問題