# How to write an if-else statement in a JSP page?

JSPJava 8Object Oriented ProgrammingProgramming

The if...else block starts out as an ordinary Scriptlet, but the Scriptlet is closed at each line with HTML text included between the Scriptlet tags.

## Example

Live Demo

<%! int day = 3; %>
<html>
<title>IF...ELSE Example</title>
<body>
<% if (day == 1 || day == 7) { %>
<p> Today is weekend</p>
<% } else { %>
<p> Today is not weekend</p>
<% } %>
</body>
</html>

The above code will generate the following result −

Today is not weekend
Updated on 30-Jul-2019 22:30:25