@Component ("User") @Scope ("Prototype") Public classUseractionextendsActionsupportImplementsModeldriven {PrivateUserregisterinfo info =NewUserregisterinfo (); PrivateUsermanager um; PrivateList<user>users; PublicUsermanager getum () {returnum; } @Resource (Name= "Usermanager") Public voidsetum (Usermanager um) { This. um =um; } @Override PublicString Execute ()throwsException {User u=NewUser (); U.setusername (Info.getusername ()); U.setpassword (Info.getpassword ()); if(Um.exists (U)) {return"Fail"; } um.add (U); return"Success"; } Publicuserregisterinfo GetInfo () {returninfo; } Public voidsetInfo (userregisterinfo info) { This. info =info; } //@Override PublicObject Getmodel () {returninfo; } PublicString list () { This. Users = This. Um.getusers (); return"List"; } PublicList<user>getusers () {returnusers; } Public voidSetusers (list<user>users) { This. Users =users; } }
Realize
Implements Modeldriven This interface, in the JSP page can not add xxx.username, directly write username can
Questions about encapsulating form forms in Struts2