2013-10-22 48 views
1

我在做一個JSP/servlet項目。我的一些隊友喜歡存儲文本消息,這些消息用於通過<c:set scope="page"/>呈現字符串變量中的頁面內容。這是一個很好的做法嗎?如果不是,那麼不這樣做的原因是什麼?在JSP中聲明實例變量是一種很好的做法嗎?

+0

儘量避免在JSP中聲明變量。您可以使用JSTL標記 –

回答

1

我不會稱之爲不好的做法,特別是在page範圍內使用時。

<c:set var="myVariable" scope="page" 
     value="${myBean.someProperty.anotherProperty}" /> 
Value of A is ${myVariable.a} 
Value of B is ${myVariable.b} 
Value of C is ${myVariable.c} 

Value of A is ${myBean.someProperty.anotherProperty.a} 
Value of B is ${myBean.someProperty.anotherProperty.b} 
Value of C is ${myBean.someProperty.anotherProperty.c} 

更具可讀性但是,如果你正在使用它來存儲短信,更好的選擇很可能會在你的JSP UND用它來使用Message Bundlefmt標籤可以用於此。

+0

事實上,Grails使用來實現本地化消息的功能。 – shihpeng

相關問題