About Question com.enthuware.ets.scwcd.v5.2.142 :

Moderator: admin

Post Reply
ETS User

About Question com.enthuware.ets.scwcd.v5.2.142 :

Post by ETS User »

Which of the following are correct JSP scriptlet?

1.
<% int i = 10; %>
System.out.println("starting loop");
<%for(i=0; i< 10; i++) { out.println(i); } %>

2.
<% int i = 0; %>
<% System.out.println("starting loop");%>
<% for(int i=0; i< 10; i++) { out.println(i); } %>

3.
<% int i = 0, s = 0;
System.out.println("starting loop");
for(; i< 10; i++) { s+=i; } %>

4.
<%
System.out.println("starting loop");
for(int i=0; i< 10; i++) {%> looping <%} %>


It says 1, 3 and 4. are correct but "System.out.println("starting loop");" of first scriplet it outside <% %> is this correct?

admin
Site Admin
Posts: 10090
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scwcd.v5.2.142 :

Post by admin »

Yes, 1 is valid. As the explanation says:
Although System.out.println("starting loop"); is not HTML but if you don't put it inside <% %>, it will be considered as HTML. It won't cause any compile or runtime problems as the JSP parser will not even look at it. This line will be output as is to the browser. So 1 is valid.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests