I get a "Duplicate Local Variable" error in JSP after build in RAD. I have same variable names inside scriptlet tags different logic:present / logic iterate tags. 
Sample code.
<logic:present> 
<%
  int var1 = 5;
%>
</logic:present>
...................
<logic:present> 
<%
  int var1 = 5;
%>
</logic:present> 
  Since the variable are in different scope, they are not duplicates. Are the variables in the same scope ? If not, is it some compilation / validation problem in RAD ? Please advise.
 
    
    - 779
- 4
- 17
- 31
2 Answers
RAD is right. You're using scriptlets (those old fashioned <% %> things which should be avoided) instead of taglibs (for example <prefix:name>) to work with server side data. The scriptlets doesn't run in the same scope as those taglibs as you seem to expect. All scriptlets declared by <% %> share the same local scope. Get rid of them and replace them by the appropriate taglibs. Since the functional requirement is unclear, it's hard to give you a well suited code example of the correct approach.
They are indeed in the same scope they wouldn't if it were like this for example:
<logic:present> 
  <% {int var1 = 5; }%>
 </logic:present>
 ................... 
<logic:present> 
  <% int var1 = 5; %>
 </logic:present>
In the end everything will be translated into one method, thats why your code assistent generates you an error. Anyway as BalusC said it is not recommended to use scriptlets.
 
    
    - 4,834
- 5
- 44
- 65
 
    