In Struts 2, the is a core component that allows an Action class to delegate data handling to a separate model object rather than using its own fields. It is part of the defaultStack of interceptors, meaning it is applied to all actions by default unless manually overridden. Key Functions
: The ModelDrivenInterceptor must appear before the ParametersInterceptor in the stack to ensure the model is on the stack before parameters are applied to it. Model Driven Interceptor In Struts2 Example
public class User { private String username; private String email; // Getters and Setters public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } } Use code with caution. Copied to clipboard In Struts 2, the is a core component
To use this interceptor, your Action must implement the com.opensymphony.xwork2.ModelDriven interface and provide a getModel() method. public class User { private String username; private
import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.ModelDriven; public class LoginAction extends ActionSupport implements ModelDriven { // Model object must be initialized private User user = new User(); @Override public User getModel() { return user; } public String execute() { // Business logic uses the populated 'user' object return SUCCESS; } } Use code with caution. Copied to clipboard Configuration and Best Practices
: The model object returned by getModel() must not be null; otherwise, the interceptor will ignore it and not push it onto the stack.