java - Using Expression language under javascript? -
i have below checkbox in jsp file
<input type="checkbox" name="vehicle" value="bike" onclick="javascript:selectcustomers(${sessionscope.custid});">
getting following error:
org.apache.jasper.jasperexception: customer.jsp(1419,33) according tld or attribute directive in tag file,
attribute onclick not accept expressions
can not use expression language in javascript (in case under onclick()
event)?
when jsp page called, following happens, in order:
- server checks see if .jsp has been compiled , whether or not has changed since last compiled.
- server runs jsp through jasper compiler, interprets jsp java code, not java (css, html, javascript, etc) placed in string.
- the java code compiled , executed.
- the results placed in response , sent user.
so, statement: ${sessionscope.custid}
executed before the html sent user, , input of selectcustomers()
function set before calling it.
for more info have @ post jsp inside listitems onclick
how verify it?
right click in browser , @ view source.
try below sample code might you.
enclose ${...}
inside single quotes.
<c:set var="custid" value="1234" scope="session" /> before : <c:out value="${sessionscope.custid}"></c:out> <input type="checkbox" name="vehicle" value="bike" onclick="javascript:selectcustomers('${sessionscope.custid}');"> <c:set var="custid" value="4321" scope="session" /> after: <c:out value="${sessionscope.custid}"></c:out>
view source code: (right click in browser view it)
before : 1234 <input type="checkbox" name="vehicle" value="bike" onclick="javascript:selectcustomers('1234');"> after: 4321
Comments
Post a Comment