Javatpoint Logo
Javatpoint Logo

Struts 2 modelDriven interceptor example

The modelDriven interceptor makes other model object as the default object of valuestack.

Bydefault, action object is the default object of valuestack.

To use the modelDriven interceptor, you need to implement ModelDriven interface in your action class and override its method getModel().

It is found in the default stack bydefault. So you don't need to specify it explicitely.

Parameters of modelDriven interceptor

There is no parameter defined for modelDriven interceptor.

Example of modelDriven interceptor


Full example of modelDriven interceptor

Let's see the full example of modelDriven interceptor.

File: index.jsp
File: struts.xml
File: Login.java
File: User.java
File: login-success.jsp
File: login-error.jsp

Output

struts 2 modeldriven interceptor example output 1 struts 2 modeldriven interceptor example output 2

If you don't implement the ModelDriven interface, you need to use user.name and user.password field names in index.jsp file otherwise given value will not be set.






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA