Consider this example:
<% int testNumber = 1; %>
//Some HTML goes here
<%=testNumber%>
I get compile error:
testNumber cannot be resolved to a variable
Can someone explain what is going on?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need to make sure that you understand variable scoping. It’s in scriptlets the same as in normal Java classes.
So if you actually have for example
Then you will get exactly this error (also in a normal Java class!). To fix this, you’d need to make sure that the variable is declared in the very same scope, if necessary with a default value.
Unrelated to the concrete problem, using scriptlets is considered poor practice.