Search code examples
jspduplicatesrad

Duplicate local variable in JSP in RAD


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.


Solution

  • 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.