Is there a way I can get a attribute set in ServletContext
in EL so that it ends up as a JavaScript variable?
I am setting it as
context.setAttribute("testing.port", "9000");
I tried retrieving it like
alert("port" +'${testing.port}');
I am just getting a blank.
The problem is the period (.
) in the key name. EL interprets the period as a call to an accessor method named getPort
1 on whatever object testing
references. Fetch the value from the appropriate implicit object:
${applicationScope['testing.port']}
or just use a different key:
${testingPort}
1Yes, this is a simplification of what really happens. It may also look for a predicate getter named isPort
, or try Map#get("port")
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With