2008-09-18 135 views
-1

我使用的是freemarker,SiteMesh和Spring框架。 對於我使用$ {requestContext.getMessage()}從message.properties中獲取消息的頁面。但對於裝飾者來說,這是行不通的。我應該怎麼做才能讓sitemesh的國際化工作?國際化sitemesh

+0

你是什麼意思時,你說什麼它「不起作用」?您是否收到特定的錯誤訊息?它會從「大英百科全書」中返回一個隨機頁面而不是你想要的信息嗎?它退出了嗎?它掛了嗎?它會召喚Yog Sothoth嗎? – 2018-03-05 04:36:02

回答

2

您必須使用fmt taglib。

首先,爲sitemesh添加taglib,並將fmt添加到修飾器的fisrt行。

<%@ taglib prefix="decorator" uri="http://www.opensymphony.com/sitemesh/decorator"%> 
<%@ taglib prefix="page" uri="http://www.opensymphony.com/sitemesh/page"%> 
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%> 
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt"%> 
<fmt:setBundle basename="messages" /> 

在我的例子中,i18n文件是messages.properties。然後你需要使用fmt標籤來使用消息。

<fmt:message key="key_of_message" /> 
0

如果你喜歡模板和freemarker中的servlet相反,你可以在你的模板中輸入以下內容:

<#assign fmt=JspTaglibs["http://java.sun.com/jstl/fmt"]> 
<@fmt.message key="webapp.name" /> 

,並在您web.xml

<context-param> 
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name> 
    <param-value>messages</param-value> 
</context-param>