[an error occurred while processing this directive]

Use while loop in jsp code

                         

While loop is a control flow statement that works repeatedly based on a given boolean condition, loop will continuously execute the statements given in the body as long as a given condition is true.

 

 

 

 

While loop checks the condition before the body execution so this is also called pre test loop. This is the main difference between while and do while loop, do while loop first execute the loop body then checks the boolean condition.

Before run this jsp code create a new directory named "user" in the tomcat-6.0.16/webapps and paste WEB-INF directory in same.

while_statement.jsp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
  <HEAD>
    <TITLE>Using the while Loop in jsp</TITLE>
  </HEAD>
  <BODY>
    <H1>Using the while Loop</H1>
    <%  
	out.println("Loop will run 5 times.<br>");
        int i = 1;
	// while loop that runs five times
        while (i<6) {
            out.println("we are in loop value is : "+i+"<br>");
	    i++;
        }
        out.println("Now we are out of while loop.");
    %>
  </BODY>
</HTML>

Rum tomcat server by clicking on startup.bat file in bin directory ob tomcat. Save this code as a .jsp file named "while_statement.jsp" in the directory Tomcat-6.0.16/webapps/user/ and you can run this jsp page with following url in address bar of the browser http://localhost:8080/user/while_statement.jsp 

Download Source Code

                         

[an error occurred while processing this directive]