Implementing Conditional Content on a JSP Page

We make use of the condition to check if the entered value is correct.

Implementing Conditional Content on a JSP Page

Implementing Conditional Content on a JSP Page

        

We make use of the condition to check if the entered value is correct. It correct then what will be the output, and in case if it is wrong then what output will be displayed to the browser.

In this program we are using the switch statement to check the conditions. In this program we are making the using of html form. When the values are entered in the html form then these values are checked by the controller, then on checking the values the output will be displayed to the user.

The code of the program is given below:

 

 

 

<html>
	<head>
		<title>Conditional Test</title>
	</head>
	<body>

<form method = "get" action = "Conditional.jsp">
 Enter the number<input type 
             = "text" name = "number" value = "">
<input type = "submit" name = "submit" value = "submit">

		</form>
	</body>
</html>

 

<% switch (Integer.parseInt(request.getParameter("number"))) {
        case 0: %>
           You have entered the number 0
    <%     break;
        case 1: %>
           You have entered the number 1
    <%     break;
        default: %>
           You can enter either o or 1
    <% } %>

The output of the program is given below:

When the number entered is correct.

When the number entered is wrong.

Download this example.