【发布时间】:2011-11-30 04:00:05
【问题描述】:
有没有办法让我在 EL 的 ServletContext 中设置一个属性,以便它最终成为一个 JavaScript 变量?
我设置为
context.setAttribute("testing.port", "9000");
我试着像检索它一样
alert("port" +'${testing.port}');
我只是得到一个空白。
【问题讨论】:
有没有办法让我在 EL 的 ServletContext 中设置一个属性,以便它最终成为一个 JavaScript 变量?
我设置为
context.setAttribute("testing.port", "9000");
我试着像检索它一样
alert("port" +'${testing.port}');
我只是得到一个空白。
【问题讨论】:
问题在于密钥名称中的句点 (.)。 EL 将句点解释为对 testing 引用的任何对象上名为 getPort1 的访问器方法的调用。 Fetch the value from the appropriate implicit object:
${applicationScope['testing.port']}
或者只是使用不同的密钥:
${testingPort}
1是的,这是对实际情况的简化。它还可能会寻找名为isPort 的谓词getter,或尝试Map#get("port")。
【讨论】:
${servletContext} 不存在。有${pageContext.servletContext},但这不是你想要的。另见stackoverflow.com/tags/el/info 和docs.oracle.com/javaee/5/tutorial/doc/bnahq.html#bnaij