Apache Struts is an open-source web application framework developed by the Apache Software Foundation for building Java-based web applications. It is based on the MVC (Model-View-Controller) architecture, which separates business logic, presentation logic, and user input handling into different components.
- Integrates well with Java EE technologies such as Servlets and JSP.
- Provides centralized request processing through a controller servlet.
- Supports flexible and extensible application design.
Struts Framework Architecture
Shows how a client request flows through the Controller, Model, and View components in the Struts MVC framework.

The diagram illustrates how a request flows through the Struts MVC framework.
Components of Struts Framework
The main components of the Struts framework are:
1. Action Class
An Action class processes user requests and executes business logic.
public class LoginAction extends Action {
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
return mapping.findForward("success");
}
}
2. ActionForm
ActionForm is used to collect data entered by the user.
public class LoginForm extends ActionForm {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
3. JSP Pages
JSP pages are used to display information and collect user input.
<html:form action="/login">
Username:
<html:text property="username"/>
Password:
<html:password property="password"/>
<html:submit value="Login"/>
</html:form>
4. Configuration File
The struts-config.xml file defines mappings between requests and action classes.
<action-mappings>
<action
path="/login"
type="com.demo.LoginAction"
name="LoginForm">
<forward
name="success"
path="/success.jsp"/>
</action>
</action-mappings>
Working of Struts Framework
The working of Struts can be understood through the following steps:
1. HTTP Request from Client
- A user performs an action such as clicking a link or submitting a form.
- This generates an HTTP Request.
2. Controller (Servlet)
- The Controller acts as the central request handler.
- It receives all incoming requests from clients.
3. struts-config.xml
- This configuration file contains action mappings and navigation rules.
- It tells the controller which action class should handle a particular request.
4. Dispatch to Business Logic
- Based on the configuration, the controller dispatches the request to the appropriate Business Logic component.
- Business logic performs the required operations such as database access, calculations, or validations.
5. Update Model (Application State)
- After processing, the business logic updates the Model.
- The model represents the application's data and current state.
6. Forward to View (JSP)
- The controller forwards the processed request to a JSP View.
- The view retrieves data from the model using tags and JavaBeans.
7. Generate HTTP Response
- The JSP page generates the final HTML output.
- The response is sent back to the client browser as an HTTP Response.
Advantages of Struts Framework
- Follows MVC Architecture: Separates business logic, presentation, and control logic, making applications easier to maintain.
- Improves Code Reusability: Components such as Action classes and JSP pages can be reused across the application.
- Easy Maintenance: Changes in one layer have minimal impact on other layers.
- Built-in Form Validation: Provides validation mechanisms to reduce manual coding.
- Supports Internationalization (i18n): Makes it easier to develop multilingual applications.
- Centralized Request Handling: All requests are managed through a single controller servlet.
- Rich Tag Libraries: Offers custom JSP tags that simplify UI development.