Public class extends Actionsupport implements modeldriven<user> { private User user = new user (); Public User Getmodel () { return user; } @Override Publicthrows Exception { System.out.println (user); return NONE;} }
<form action= "${pagecontext.request.contextpath}/user3.action" method= "POST" > User name <input type= "text" Name= " Username "/><br/> password <input type=" password "name=" password "/><br/><input type=" Submit "value= "Submit"/></form>
Page:
User name: <input type= "text" name= "username" ><br/>
Action:
public class ParamAction3 extends Actionsupport implements modeldriven<user>{
Private User user = new user ();
Public User Getmodel () {
return user;
}
}
Implementation modeldriven<t> must manually build the encapsulated object.
* Model-driven use is the most extensive. A separate interceptor is provided in the STRUTS2 to complete the model-driven encapsulation, and some of the structures in the Struts2 are designed around model-driven.
Compare the second and third ways:
* The third type uses more. The second is more flexible. The third model-driven approach can only be encapsulated into one entity object. The second way is encapsulated into different entities.
* The third way to provide interceptors:
<interceptor name= "Modeldriven" class= "Com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor"/>
* The second package to different entities:
<input type= "text" name= "User.username" >
<input type= "text" name= "Product.price" >
STRUTS2 Model Driven