欢迎来到天天文库
浏览记录
ID:15996168
大小:53.00 KB
页数:15页
时间:2018-08-07
《web常用工具类总结》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、表单后台验证;packagecn.kgli.utils;importjava.util.Enumeration;importjava.util.UUID;importjavax.servlet.http.HttpServletRequest;importorg.apache.commons.beanutils.BeanUtils;publicclassWebUtils{//把request对象中的请求参数封装到bean中publicstaticTrequest2Bean(HttpServletRequestrequest,Classclazz){try{T
2、bean=clazz.newInstance();//username=aapassword=bbemail=aa@sina.comEnumeratione=request.getParameterNames();while(e.hasMoreElements()){Stringname=(String)e.nextElement();//username=aaapassword=123Stringvalue=request.getParameter(name);BeanUtils.setProperty(bean,name,value);}returnbean;}c
3、atch(Exceptione){thrownewRuntimeException(e);}}publicstaticStringmakeId(){//UUID12836位字符returnUUID.randomUUID().toString();}}packagecn.itcast.web.formbean;importjava.util.HashMap;importjava.util.Map;importorg.apache.commons.beanutils.locale.converters.DateLocaleConverter;publicclassRegi
4、sterFormBean{privateStringusername;privateStringpassword;privateStringpassword2;privateStringemail;privateStringbirthday;privateMaperrors=newHashMap();publicMapgetErrors(){returnerrors;}publicvoidsetErrors(Maperrors){this.errors=errors;}publi
5、cStringgetUsername(){returnusername;}publicvoidsetUsername(Stringusername){this.username=username;}publicStringgetPassword(){returnpassword;}publicvoidsetPassword(Stringpassword){this.password=password;}publicStringgetPassword2(){returnpassword2;}publicvoidsetPassword2(Stringpassword2){
6、this.password2=password2;}publicStringgetEmail(){returnemail;}publicvoidsetEmail(Stringemail){this.email=email;}publicStringgetBirthday(){returnbirthday;}publicvoidsetBirthday(Stringbirthday){this.birthday=birthday;}/*privateStringusername;用户名不能为空,并且要是3-8的字符abcdABcdprivateStringpassword
7、;密码不能为空,并且要是3-8的数字privateStringpassword2;两次密码要一致privateStringemail;可以为空,不为空要是一个合法的邮箱privateStringbirthday;可以为空,不为空时,要是一个合法的日期**/publicbooleanvalidate(){booleanisOk=true;if(this.username==null
8、
9、this.username.trim().equals("")){isOk=false;errors.put("username","用户名不能为空!!");}else{
此文档下载收益归作者所有