直接在struts的form里面使用正则表达式验证合法性,个人比较方便
不用去配置那么多的东西,直接验证,不合法直接返回,合法再进入
action流程.
public ActionErrors validate( ActionMapping mapping, HttpServletRequest request) { ActionErrors errors=new ActionErrors(); String pattern = "[\u4e00-\u9fa5]"; boolean check = StaticFunction.checkByRegExp(pattern,faceContent.getFileName()); if(check){ errors.add("file",new ActionError("error.file.chinese")); } return errors; } |