2013-10-22 104 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

相关问题