Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I print a servlet context attribute in EL?

Tags:

servlets

el

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.

like image 974
Abhishek Avatar asked Nov 30 '11 04:11

Abhishek


1 Answers

The problem is the period (.) in the key name. EL interprets the period as a call to an accessor method named getPort1 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").

like image 62
Matt Ball Avatar answered Nov 09 '22 17:11

Matt Ball