JSP runs at webserver and generates/produces HTML/CSS/JS code upon a webbrowser request. Webserver sends HTML/CSS/JS to webbrowser. Webbrowser runs HTML/CSS/JS. So, you just have to let JSP print it literally as JS code.
<script language="javascript">
function bustOut(){
var newWin = window.open("the real url", "subWindow","height=500,width=700,resizable=yes,scrollbars=yes");
}
<%
if (foo != null) {
out.print("bustOut();");
}
%>
</script>
or, better, with EL
<script language="javascript">
function bustOut(){
var newWin = window.open("the real url", "subWindow","height=500,width=700,resizable=yes,scrollbars=yes");
}
${not empty foo ? 'bustOut();' : ''}
</script>
(note that I changed the attribute name to foo
because request
stands for HttpServletRequest
which might confuse others since this is never null
)
Either way, the generated HTML (which you should see by opening page in browser, rightclicking it and choosing View Source) should look like this when the condition was true:
<script language="javascript">
function bustOut(){
var newWin = window.open("the real url", "subWindow","height=500,width=700,resizable=yes,scrollbars=yes");
}
bustOut();
</script>
Does it now turn on a light bulb above your head?