admin管理员组文章数量:1332395
I have below CheckBox in JSP file
<input type="checkbox" name="vehicle" value="Bike"
onclick="javascript:selectCustomers(${sessionScope.custId});">
Getting the following error:
org.apache.jasper.JasperException: customer.jsp(1419,33) According to TLD or attribute directive in tag file,
attribute onclick does not accept any expressions
Can we not use expression language in JavaScript (in my case under onClick()
Event)?
I have below CheckBox in JSP file
<input type="checkbox" name="vehicle" value="Bike"
onclick="javascript:selectCustomers(${sessionScope.custId});">
Getting the following error:
org.apache.jasper.JasperException: customer.jsp(1419,33) According to TLD or attribute directive in tag file,
attribute onclick does not accept any expressions
Can we not use expression language in JavaScript (in my case under onClick()
Event)?
-
BTW: you can remove
javascript:
as it is just nonsense label in this context -onclick="anything:selectCustomers();"
works too. – user11153 Commented Jun 27, 2014 at 11:16
2 Answers
Reset to default 3When a JSP page is called, the following happens, in this order:
- Server checks to see if the .jsp has already been piled and whether or not it has changed since it was last piled.
- Server runs the jsp through the Jasper piler, which interprets the jsp into Java code, anything that is not Java (CSS, HTML, JavaScript, etc) is placed in a String.
- The Java code is piled and executed.
- The results are placed in the response and sent to the user.
So, your statement: ${sessionScope.custId}
is executed before the the HTML is sent to the user, and the input of selectCustomers()
function is already set to before calling it.
For more info have a look at my another post JSP inside ListItems onclick
How to verify it?
Right click in the browser and look at the view source.
Try below sample code that might help you.
Enclose ${...}
inside the 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 to view it)
Before : 1234
<input type="checkbox" name="vehicle" value="Bike"
onclick="javascript:selectCustomers('1234');">
After: 4321
Try this:
<input type="hidden" id="custId" name="custId" value="${sessionScope.custId}">
<input type="checkbox" name="vehicle" value="Bike" onclick="javascript:selectCustomers();">
function selectCustomers(){
var custId = document.getElementById('custId').value;
}
本文标签: javaUsing Expression language under javascriptStack Overflow
版权声明:本文标题:java - Using Expression language under javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742281396a2446160.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论