Introduction
Hey, Ninja, let us begin with the introduction of If and Else Tags. So, The If Else tag is used in the struts web application to compare several situations. As a result, the code will be executed along with the appropriate condition.

Tag for Struts Control - If and Else Example
Create action class
package com.codingninjas.struts2;
public class NinjaAction {
private String fullname;
public String execute() throws Exception {
return "success";
}
public String getNfullame() {
return fullname;
}
public void setfullName(String fullname) {
this.fullname = fullname;
}
}
Create Views
Let's look at the index.jsp file as shown below:
<%@ page language = "java" contentType = "text/html; charset = ISO-8859-1"
pageEncoding = "ISO-8859-1"%>
<%@ taglib prefix = "s" uri = "/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"https://www.codingninjas.com/">
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1>Struts2</h1>
<form action = "hello">
<label for = "fullname">Pick a name</label><br/>
<select fullname = "fullname">
<option fullname = "Burge">Burge</option>
<option fullname = "Sagar">Sagar</option>
<option fullname = "Leon">Leon</option>
</select>
<input type = "submit" value = "Say Hi"/>
</form>
</body>
</html>
Let's go on to HelloWorld.jsp to see how to use the if and else, and elseif tags.
<%@ page contentType = "text/html; charset = UTF-8" %>
<%@ taglib prefix = "s" uri = "/struts-tags" %>
<html>
<head>
<title>If and Else Example</title>
</head>
<body>
<b>If and Else Example</b><br/>
<s:if test = "fullname=='Burge'">
You have selected 'Burge'.
</s:if>
<s:elseif test = "fullname=='sagar'">
You have selected 'sagar'
</s:elseif>
<s:else>
You have not selected 'Burge' or 'sagar'.
</s:else>
</body>
</html>
In this case, the "if" tag returns true if the "test" attribute's condition is satisfied. In this instance, we are contrasting it with "Mike." The tag returns true if the name is Mike, in which case the string is printed. If not, the "elseif" block is executed, and if that condition is not met, the else block is then carried out. This is identical to the standard if, else if, and else constructs found in the Java language.
Files for Configuration
Your struts.xml should appear as follows:
<?xml version = "1.0" Encoding = "UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name = "struts.devMode" value = "true" />
<package name = "helloworld" extends = "struts-default">
<action name = "hello"
class = "com.codingninjas.HelloWorldAction"
method = "execute">
<result name = "success">/HelloWorld.jsp</result>
</action>
</package>
</struts>
Your web.xml should appear as follows:
<?xml version = "1.0" Encoding = "UTF-8"?>
<web-app xmlns:xsi = "https://www.codingninjas.com/XMLSchema-instance"
xmlns = "http://java.sun.com/xml/ns/javaee"
xmlns:web = "http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation = "http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id = "WebApp_ID" version = "3.0">
<display-name>Struts 2</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
To produce a War file, perform right-click on the project name and select Export > WAR File. After that, deploy this WAR to the webapps directory of Tomcat. Launch Tomcat server. This will result in the screen shown below: