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?
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?
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
<%
if (someCondition) {
int testNumber = 1;
}
%>
...
<%=testNumber%>
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.
<%
int testNumber = 0;
if (someCondition) {
testNumber = 1;
}
%>
...
<%=testNumber%>
Unrelated to the concrete problem, using scriptlets is considered poor practice.
Design problems aside, try declaring the variable as a global:
<%! int testNumber = 0; %>