有没有办法ServletContext在EL中设置属性,以便最终成为JavaScript变量?
我把它设为
context.setAttribute("testing.port", "9000");
Run Code Online (Sandbox Code Playgroud)
我尝试检索它
alert("port" +'${testing.port}');
Run Code Online (Sandbox Code Playgroud)
我只是一片空白.
问题是.密钥名称中的句点().EL将句点解释为对任何对象引用的名为getPort1的访问器方法的调用testing.从适当的隐式对象中获取值:
${applicationScope['testing.port']}
Run Code Online (Sandbox Code Playgroud)
或者只是使用不同的密钥:
${testingPort}
Run Code Online (Sandbox Code Playgroud)
1是的,这是对实际情况的简化.它也可以查找名为getter的谓词getter isPort,或者尝试Map#get("port").