开发者

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; %> </logi开发者_如何学Goc: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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜