Client Programming
Assignment
Submitted by
Akalya E
Leave Application System using Struts 2 Framework
Apache Struts is an open-source Java web application framework used to develop dynamic
web applications. It is based on the Model View Controller (MVC) architecture, which
separates application logic, user interface, and control flow.
MVC Architecture in Struts
Model
● Contains business logic and data
● Implemented using simple Java classes (POJO)
View
● Responsible for user interface
● Developed using JSP, HTML, and tag libraries
Controller
● Handles user requests and responses
● Managed by Struts 2 framework using filters
Key Components of Struts
1. Action Class
● Core component of Struts 2
● Acts as Controller and Model
● Written as a normal Java class
2. JSP (Java Server Pages)
● Used to design the user interface
● Displays data to the user
3. [Link]
● Main configuration file
● Defines action mappings and result pages
4. [Link]
● Deployment descriptor
● Configures Struts filter to handle requests
5. Interceptors
● Used to process requests before and after action execution
● Handles validation, logging, etc.
Working flow
1. User sends request from browser
2. Request goes to Struts filter ([Link])
3. Filter checks mapping in [Link]
4. Corresponding Action class is executed
5. Business logic is processed
6. Action returns result (e.g., "success")
7. Result page (JSP) is displayed
Project structure
Code
[Link]
<project xmlns="[Link]
<modelVersion>4.0.0</modelVersion>
<groupId>[Link]</groupId>
<artifactId>LeaveApp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>[Link]</groupId>
<artifactId>struts2-core</artifactId>
<version>2.5.33</version>
</dependency>
<dependency>
<groupId>[Link]</groupId>
<artifactId>[Link]-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
[Link]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"[Link]
<struts>
<package name="default" namespace="/" extends="struts-default">
<action name="applyLeave" class="[Link]">
<result name="success">/[Link]</result>
</action>
</package>
</struts>
[Link]
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="[Link]
xmlns:xsi="[Link]
xsi:schemaLocation="[Link]
[Link]
version="4.0">
<filter>
<filter-name>struts2</filter-name> <filter-
class>[Link]</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
LeaveAction
package [Link];
public class LeaveAction {
private String name;
public String execute() {
[Link]("Leave Applied by: " + name);
return "success";
}
public String getName() { return name; }
public void setName(String name) { [Link] = name; }
}
[Link]
<div style="width:400px; margin:auto;">
<h2 style="text-align:center;">Leave Application Form</h2>
<form action="[Link]" method="post">
Name: <input type="text" name="name"><br><br>
From: <input type="date" name="fromDate"><br><br>
To: <input type="date" name="toDate"><br><br>
Reason: <textarea name="reason"></textarea><br><br>
<input type="submit" value="Apply">
</form>
</div>
[Link]
<h2>Leave Applied Successfully</h2>
Output
Shows a Build Success in IntelliJ and Maven packages the project into a .war file.
Shows the empty Leave Application Form loaded at [Link].
Shows the form populated with user data (Name, Date, Reason) just before submission.
Displays the [Link] page with the message "Leave Applied Successfully" after the Struts
action completes.
Displays the Tomcat server console logs, confirming the deployment and printing the action's
output: "Leave Applied by: Akalya E".