views:

33

answers:

2

I don't understand why the first program in JSP is working, but the second program is giving an error:

<% for(int i=0;i<10;i++){

out.print("hello");
}
%>


<% for(int i=0;i<10;i++){

<%= "hello" %>
}
%>
+2  A: 

At a guess, it is because you can't nest '%<' tags.

Jonathan Leffler
Also, putting EL expression inside '<%' tags again giving me an error. Why? Is it mean we can't put EL expression inside '<%' tags?
Dusk
+1 for good guess :-) And no, EL expression can not be put within `<%` tags anymore than it can be put in your java class - everything within `<% %>` tags is taken "as is" and inserted in generated JSP as java code.
ChssPly76
+1  A: 

Try it like this:

<% for(int i=0;i<10;i++){
out.print("hello");
}
%>

<% for(int i=0;i<10;i++){ %>
<%= "hello" %>
<%
}
%>
Asaph