显示注册信息
package j2ee0525; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class RegisterServlet extends HttpServlet { /** * The doGet method of the servlet. <br> * * This method is called when a form has its tag value method equals to get. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request, response); } /** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //获得请求方式 System.out.println("请求方法:"+request.getMethod()); System.out.println("URL"+request.getRequestURL()); System.out.println("ip:"+request.getRemoteAddr()); String name=request.getParameter("userName"); System.out.println("userName:"+name); String pwd=request.getParameter("password"); String sex=request.getParameter("sex"); System.out.println("pwd:"+pwd+","+"sex:"+sex); response.setContentType("text/html charset=UTF-8"); PrintWriter out = response.getWriter(); out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); out.println("<HTML>"); out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>"); out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close(); } }
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>reg.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <!--<link rel="stylesheet" type="text/css" href="./styles.css">--> </head> <body> <form action="reg" method="get"> userName<input type="text" name="userName"/><br/> password<input type="password" name="password"/><br/> sex<input type="radio" name="sex" value="male" checked/>男 <input type="radio" name="sex" value="femal" checked/>女<br/> <input type="submit" value="注册"/> </form> </body> </html>