问题描述
下面是注册表的各个代码:(1)注册验证Bean-------Register.javapackagemyjavabean;importjava.util.*;importjava.util.Map;publicclassRegister{privateStringname;privateStringage;privateStringemail;privateMap<String,String>errors=null;publicRegister(){this.name="";this.age="";this.email="";}publicbooleanisValidate(){booleanflag=true;if(!this.name.matches("\w{6,15}")){flag=false;this.name="";errors.put("errname","用户名是6-15位字母或数字");}if(!this.age.matches("\d+")){flag=false;this.age="";errors.put("errage","年龄只能是数字");}if(!this.email.matches("\w+@\w+\.\w+\.?\w*")){flag=false;this.email="";errors.put("erremail","输入的email地址不合法");}returnflag;}publicStringgetErrorMsg(Stringkey){Stringvalue=this.errors.get(key);returnvalue==null?"":value;}publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}publicStringgetAge(){returnage;}publicvoidsetAge(Stringage){this.age=age;}publicStringgetEmail(){returnemail;}publicvoidsetEmail(Stringemail){this.email=email;}}(2)注册表单页-----index.jsp<body> <%request.setCharacterEncoding("UTF-8");%><jsp:useBeanid="reg"scope="request"class="myjavabean.Register"></jsp:useBean><formaction="check.jsp"method="post">用户名:<inputtype="text"name="name"value="<jsp:getPropertyname="reg"property="name"/>"><%=reg.getErrorMsg("errname")%><br>年 龄:<inputtype="text"name="age"vlaue="<jsp:getPropertyname="reg"property="age"/>"><%=reg.getErrorMsg("errage")%><br>Email<inputtype="text"name="email"value="<jsp:getPropertyname="reg"property="email"/>"><%=reg.getErrorMsg("erreamil")%><br><inputtype="submit"value="注册"><inputtype="reset"value="重置"></form></body>(3)信息验证页-----check.jsp<body><%request.setCharacterEncoding("UTF-8");%><jsp:useBeanid="reg"scope="request"class="myjavabean.Register"></jsp:useBean><jsp:setPropertyname="reg"property="*"/><%if(reg.isValidate()){%><jsp:forwardpage="success.jsp"/><%}else{%><jsp:forwardpage="index.jsp"></jsp:forward><%}%></body>(4)成功显示页-----success.jsp<body><%request.setCharacterEncoding("UTF-8");%><jsp:useBeanid="reg"scope="request"class="myjavabean.Register"/>用户名:<jsp:getPropertyname="reg"property="name"/><br>年 龄:<jsp:getPropertyname="reg"property="age"/>Email:<jsp:getPropertyname="reg"property="email"/></body>现在在地址栏中输入地址,网页显示效果如下:HTTPStatus500---------------------------------------------------------------------------------typeExceptionreportmessagedescriptionTheserverencounteredaninternalerror()thatpreventeditfromfulfillingthisrequest.exceptionorg.apache.jasper.JasperException:java.lang.NullPointerExceptionorg.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:541)org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rootcausejava.lang.NullPointerExceptionmyjavabean.Register.getErrorMsg(Register.java:37)org.apache.jsp.index_jsp._jspService(index_jsp.java:99)org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)javax.servlet.http.HttpServlet.service(HttpServlet.java:803)org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)javax.servlet.http.HttpServlet.service(HttpServlet.java:803)noteThefullstacktraceoftherootcauseisavailableintheApacheTomcat/6.0.13logs.--------------------------------------------------------------------------------ApacheTomcat不知为什么会是这样,请各位予以指点。