In the Web application development, the legitimacy inspection of the input data is not more than two: 1. Client page JavaScript inspection .2. Server side, perform data inspection before performing logic code. Similar to Spring MVC, XWork also provides one Validator interface, all data check classes must implement this interface. The action of the server-side data legitimacy verification occurs before the Action is called. A ValidationInterceptor is provided in WebWork, which will call the specified Validator to legally check the input parameters. The following is an example of a user registration information legitimacy test: first let us create a new user registration Action class: RegisterAction, so that it inherits ActionSupport (ActionSupport, the Action, Validateable, Serializable, ValidationaWare, LocaleProvider interface, with data check error message, Action runs the error message save the error message). package com.wzj.rbac.webwork.action; import com.opensymphony.xwork.Action; import com.opensymphony.xwork.ActionSupport; import com.wzj.framework.spring.resource.BeanLocator; import com.wzj.rbac.ServiceFacade .UserService; import com.wzj.rbac.domain.object.user; / ** * @Desc User registration Action class (controller) * @Author chikai * @Link Chikai * @version $ registeraction.java 2004-11-12 11:50:38 $ * @Version $ project xwork * / public class registerAction extension actionsupport implements action {private userService_userService
Private user user = new user ();
public User getUser () {return this.user;} public String execute () {_userService = BeanLocator.getGlobalServiceLocator () getUserService ();. try {_userService.createUser (user);} catch (Exception e) {// log. Error ("Create User Failure", E); E.PrintStackTrace ();} Return Success;}} then creates a user-registered form page: Register.jsp. <% @ Page PageEncoding = "GB2312" ContentType = "text / html; charset = GB2312"%> <% @ Taglib prefix = "ww" URI = "Webwork"%>