资源描述:
《servlet注册程序实例》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、以上是整个工程结构,首先是工程名称是jsppractise,然后包名是com.register,其中servlet的名称是RegisterServlet,本次工程利用的开发环境是eclipse4.2tomcat6.0.33其中代码如下:控制层:RegisterServlet.javapackagecom.register;importjava.io.IOException;importjavax.servlet.RequestDispatcher;importjavax.servlet.ServletConfig;importjavax.servlet.ServletExcept
2、ion;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;/***ServletimplementationclassRegisterServlet*/publicclassRegisterServletextendsHttpServlet{publicString[]nameList;privatestaticfinallongserialVersionUID=1L;/***@s
3、eeHttpServlet#HttpServlet()*/publicRegisterServlet(){super();//TODOAuto-generatedconstructorstub}/***@seeHttpServlet#doGet(HttpServletRequestrequest,HttpServletResponseresponse)*/protectedvoiddoGet(HttpServletRequestreq,HttpServletResponseresp)throwsServletException,IOException{Stringusername
4、=(String)req.getParameter("username");Stringpassword=(String)req.getParameter("password");Stringpassword2=(String)req.getParameter("password2");if(username.equals("")
5、
6、username==null){req.setAttribute("error.message","用户名不能为空!!");RequestDispatcherreqDispatcher=req.getRequestDispatcher("/error
7、.jsp");reqDispatcher.forward(req,resp);}elseif(this.IsExist(username)){req.setAttribute("error.message","该用户已经存在!");RequestDispatcherreqDispatcher=req.getRequestDispatcher("/error.jsp");reqDispatcher.forward(req,resp);}elseif(password.equals("")
8、
9、password==null){req.setAttribute("error.messag
10、e","密码不能为空!!");RequestDispatcherreqDispatcher=req.getRequestDispatcher("/error.jsp");reqDispatcher.forward(req,resp);}elseif(!password.equals(password2)){req.setAttribute("error.message","两次输入密码不一致!!");RequestDispatcherreqDispatcher=req.getRequestDispatcher("/error.jsp");reqDispatcher.forward
11、(req,resp);}else{RequestDispatcherreqDispatcher=req.getRequestDispatcher("/success.jsp");reqDispatcher.forward(req,resp);}}/***@seeHttpServlet#doPost(HttpServletRequestrequest,HttpServletResponseresponse)*/protectedvoiddoPost(HttpServletReque