<%@ Page Language="Java"ContentType="text/html; Charset=utf-8"pageencoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Insert Title here</title></Head><Body>Register<formAction= "Zhucservlet"Method= "POST">User name<inputtype= "text"name= "username"><BR>Password<inputtype= "Password"name= "Password"><BR>Confirm Password<inputtype= "Password"name= "Password1"><BR><inputtype= "Submit"value= "Submit"></form></Body></HTML>
PackageCom.hanqi.web;Importjava.io.IOException;ImportJava.io.PrintWriter;Importjavax.servlet.ServletException;ImportJavax.servlet.http.Cookie;ImportJavax.servlet.http.HttpServlet;Importjavax.servlet.http.HttpServletRequest;ImportJavax.servlet.http.HttpServletResponse;Importjavax.servlet.http.HttpSession; Public classZhucservletextendsHttpServlet {Private Static Final LongSerialversionuid = 1L; PublicZhucservlet () {Super(); } protected voidDoget (HttpServletRequest request, httpservletresponse response)throwsservletexception, IOException {response.setcontenttype ("Text/html"); Response.setcharacterencoding ("UTF-8"); String un=request.getparameter ("username"); String PW=request.getparameter ("Password"); String PW1=request.getparameter ("Password1"); if(un!=NULL&&pw!=NULL) { if(pw!= "" &&un!= "") { if(Pw.equals (PW1)) {String n=NewString (Un.getbytes ("iso-8859-1"), "UTF-8"); Response.getwriter (). Write (n+ "Congratulations on the success of registration"); } Else{response.getwriter (). Write ("Please confirm the password is consistent"); } } Else{response.getwriter (). Write ("User name or password cannot be empty"); } } Else{response.getwriter (). Write ("User name or password cannot be empty"); } //response.getwriter (). Append ("Served at:"). Append (Request.getcontextpath ()); } protected voidDoPost (HttpServletRequest request, httpservletresponse response)throwsservletexception, IOException {doget (request, response); }}
Servlet exercises a simple registration