SnippetShare 项目总结连载(八)-在ActionForm里边做验证

 

SnippetShare 项目总结连载(八)-在ActionForm里边做验证

Luo Weifeng 2011-6-25

说明:本系列文章为作者自己看或在web开发特别初级的人看,高手和中手绕过。

 

 

只需要在ActionForm的validate函数里验证,还有就是,可以通过 Action再次验证,也就是说,有两次验证,这里是前面Form验证的部分:

 

public ActionErrors validate(ActionMapping mapping, HttpServletRequest req) { ActionErrors errors = new ActionErrors(); if (language == null || language.length() == 0) { ActionError newError = new ActionError("error.addsnippet.language.requiredfield"); errors.add(ActionErrors.GLOBAL_ERROR, newError); } // Check and see if the password is missing if (title == null || title.length() == 0) { ActionError newError = new ActionError("error.addsnippet.title.requiredfield"); errors.add(ActionErrors.GLOBAL_ERROR, newError); } if (codeSnippet == null || codeSnippet.length() == 0) { ActionError newError = new ActionError("error.addsnippet.codeSnippet.requiredfield"); errors.add(ActionErrors.GLOBAL_ERROR, newError); } if (permission == null || permission.length() == 0) { ActionError newError = new ActionError("error.addsnippet.permission.requiredfield"); errors.add(ActionErrors.GLOBAL_ERROR, newError); } if (introduction == null || introduction.length() == 0) { ActionError newError = new ActionError("error.addsnippet.introduction.requiredfield"); errors.add(ActionErrors.GLOBAL_ERROR, newError); } return errors; } 

你可能感兴趣的:(web开发,null,action)