在 JSP 中声明实例变量是一种好的做法吗?



我正在做一个JSP/servlet项目。我的一些队友喜欢存储文本消息,这些文本消息用于通过<c:set scope="page"/>在字符串变量中呈现页面内容。这是一个好的做法吗?如果没有,不这样做的原因是什么?

我不会称之为不好的做法,尤其是在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 中使用消息捆绑包并使用它。 fmt标签可用于此目的。

相关内容

最新更新