Home Jsp Simple-jsp-example Implementing Conditional Content on a JSP Page



Implementing Conditional Content on a JSP Page
Posted on: February 11, 2008 at 12:00 AM
We make use of the condition to check if the entered value is correct.

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.

Related Tags for Implementing Conditional Content on a JSP Page:
htmlcbrowserormformiooutputdisplaystateusingthiscasecheckrowcasifconditionforrowsprogramstatementtoramwsewseilitputsplbrowseinmlrmasstaconditionsmntoutplayswitchcaispemasemeprosrectspatkhtmishallandarstatssthswcondsthatdispplprndonogro


More Tutorials from this section

Ask Questions?    Discuss: Implementing Conditional Content on a JSP Page  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.