There are a number of problems with what you are trying to achieve.
The JavaScript code (inside the <script/>
tag) is executed client-side, while the JSP EL code (in the <c:when/>
tag and fn:containsIgnoreCase()
function) is executed server side.
The two bits of code do not run in the same system. They do not have visibility of one another
The two bits of code are not run at the same time. The server-side code will be executed as the HTTP response is being generated by the server and the resultant HTML will be sent back to the browser. The browser will then execute the client-side code. So although your javascript code occurs before your JSP EL code in the JSP file, they will be executed at different times - the JSP EL code will be executed first (by the server), and then the JavaScript will be executed (by the browser)
Lastly and leastly, the languages are not the same. Even if the two bits of code were to be executed in the same system, EL is not JavaScript and JavaScript is not EL. A variable declared in one language in one block will not be visible in another language in another block.
You could write all the logic you need in one language (EL), and have it executed in the sequence you want all in the same system using the pageContext.request.requestURL
or pageContext.request.requestURI
object properties