How to pass an EL variable to javascript

后端 未结 4 906
一向
一向 2020-11-30 14:44

I have a variable ${bean.name} how can i pass it to a javascript var? I\'ve tried var name = \"${bean.name}\" and var name = ${bean.name}<

4条回答
  •  一生所求
    2020-11-30 15:31

    You can't have JSTL evaluated in .js files. Only in .jsp files. (unless you remap the jsp servlet, but I wouldn't advise to do so).

    The better approach is to define the variables in the .jsp including the .js, and pass these variables as arguments to an initializing function.

    Also make sure you don't have isELIgnored="true"

提交回复
热议问题