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

Related Tutorials


 
 

Share on Google+Share on Google+

Implementing Conditional Content on a JSP Page

Advertisement
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.

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 11, 2008

Related Tutorials

Discuss: Implementing Conditional Content on a JSP Page  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com