Nesting mixed Scriptlets and HTML

jespersahner
jespersahner used Ask the Experts™
on
Hi!

This is a basic question concerning nesting mixed Scriptlets and HTML.

Say that you have some JSP-code like this:
<TABLE BORDER=2>
<%
    for ( int i = 0; i < n; i++ ) {
        %>
        <TR>
        <TD>Number</TD>
        <TD><%= i+1 %></TD>
        </TR>
        <%
    }
%>
</TABLE>

- i.e. mixed Scriptlets and HTML.

My question now is: Can mixed Scriptlets and HTML be nested?

Say that the code above should only be carried out if some condition is meet, i.e.:

<%if (some condition) { %>
  ..some mix of Scriptlet and HTML..
<% } %>

Will this work?

Regards,
Jesper
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Yes - no problems at all :)
Commented:
But much easier with JSTL.
scriplets are outdated. As rrz said, use jstl.
take a look
http://www.informit.com/articles/article.asp?p=30334&rl=1

Commented:
>scriplets are outdated  
Not really, Sometimes I like to use print method.
<TABLE BORDER=2>
<%
    for ( int i = 0; i < 6; i++ ) {
        out.print("<TR><TD>Number</TD><TD>" + i + "</TD></TR>");
    }
%>
</TABLE>
>>Not really

I know LOL :-).  Dint mean it literally.

Commented:
>scriplets are outdated  

Maybe :) But are working.
Besides sometime I love writing them... simply to remember the old days :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial