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)?

Share Improve this question edited Jun 27, 2014 at 10:44 Mr. Polywhirl 48.8k12 gold badges93 silver badges144 bronze badges asked Jun 27, 2014 at 10:36 user3198603user3198603 5,83615 gold badges78 silver badges136 bronze badges 1
  • 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
Add a ment  | 

2 Answers 2

Reset to default 3

When 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