You must put the script in JSP
<head> <script type="text/JavaScript"> $(document).ready(function() { alert(<s:property value="myVariable"/>); }); </script> </head>
you cannot use struts or other JSP tags inside js files. It is not compiled by the server. However, you can use a function in JSP that calls these scripts by passing parameters to it.
<head> <script type="text/javascript" src="<s:url value='/js/Common.js'/>"></script> <script type="text/JavaScript"> $(document).ready(function() { alertMyVariable(<s:property value="myVariable"/>); }); </script> </head>
In js:
function alertMyVariable(myVariable) { alert(myVariable); }
source share