91-9990449935 0120-4256464 |
Struts 2 modelDriven interceptor exampleThe 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 interceptorThere is no parameter defined for modelDriven interceptor. Example of modelDriven interceptorFull example of modelDriven interceptorLet'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
OutputIf 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. |