【问题标题】:How can I print a servlet context attribute in EL?如何在 EL 中打印 servlet 上下文属性?
【发布时间】:2011-11-30 04:00:05
【问题描述】:

有没有办法让我在 EL 的 ServletContext 中设置一个属性,以便它最终成为一个 JavaScript 变量?

我设置为

context.setAttribute("testing.port", "9000");

我试着像检索它一样

alert("port" +'${testing.port}');

我只是得到一个空白。

【问题讨论】:

    标签: el servlets


    【解决方案1】:

    问题在于密钥名称中的句点 (.)。 EL 将句点解释为对 testing 引用的任何对象上名为 getPort1 的访问器方法的调用。 Fetch the value from the appropriate implicit object:

    ${applicationScope['testing.port']}
    

    或者只是使用不同的密钥:

    ${testingPort}
    

    1是的,这是对实际情况的简化。它还可能会寻找名为isPort 的谓词getter,或尝试Map#get("port")

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-09
    • 2020-09-25
    相关资源
    最近更新 更多