views:

219

answers:

1

I have some JSP code, which writes a tree representing hierachical data. This data is represented using nested layers.

In the JSP code there are many code snippets similar to the following code (which outputs as many closing div tags as is the numerical value of variable differenceAmount):


<jsp:scriptlet>
    int differenceAmount = previousUserLevel - currentUserLevel;
    for(int i=0;i<differenceAmount;i++){
</jsp:scriptlet>
</div>
<jsp:scriptlet>
    }   
</jsp:scriptlet>

Using scriptlets is rather inelegant, and reading the code is also not very easy at the first sight. In what way could the code be refactored to be more readable?

+2  A: 

JSTL (the JavaServer Pages Standard Tag Library) has a foreach tag.

Guides on how to use it.

matt b