I want to display the value of variable named "id" in my code. The code is -
index.html(line 5)-
<div class="marginTable" data-pubid="<%=id%>" data-count="5">
But whenever i am executing it, it is throwing error An error occurred at line: 5 in the jsp file: /index.html id cannot be resolved to a variable. How to get out of this?
The code placed within JSP expression tag is written to the output stream of the response. So you need not write out. print() to write data. It is mainly used to print the values of variable or method.
You can declare any number of variables or methods within one declaration tag, but you have to separate them by semicolons. The declaration must be valid in the scripting language used in the JSP file. You can add method to the declaration part.
Difference between JSP Scriptlet tag and Declaration tag The jsp scriptlet tag can only declare variables not methods. The jsp declaration tag can declare variables as well as methods. The declaration of scriptlet tag is placed inside the _jspService() method.
To display the server side variables in jsp , you can use implicit object out
.
some thing like this,
<div class="marginTable" data-count="5">
<%=id%>
</div>
But using scriptlets is considered as the bad practice . so you may use EL for more info see this How to avoid Java code in JSP files? as,
${id}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With