使用Servlet实现用户注册功能

<%@ 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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

<form action="zc2" method="post">
<table align="center"width="400" height="200" border="1"cellspacing="0" cellpadding="0">
<tr><td align="center"colspan="2">填写注册信息</td></tr>
<tr><td>账号</td><td><input type="text" name="zh"></td></tr>
<tr><td>密码</td><td><input type="password" name="mm"></td></tr>
<tr><td>安全邮箱</td><td><input type="text" name="aqyx"></td></tr>
<tr><td>超级密码</td><td><input type="text" name="ccmm"></td></tr>
<tr><td  align="center"  colspan="2"><input type="submit" value="点击注册"></td></tr></table>
</form>

</body>
</html>
package com.hanqi.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class zc2 extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    
    public zc2() {
        super();
        
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html");
        response.setCharacterEncoding("UTF-8");
        
        String us=request.getParameter("zh");
        String pw=request.getParameter("mm");
        String ccmm=request.getParameter("ccmm");
        String anyx=request.getParameter("aqyx");
        if(us!=null&&pw!=null&ccmm!=null&&anyx!=null)
        {
            if(us!=""&&pw!=""&ccmm!=""&&anyx!="")
            {
                response.sendRedirect("zc3.jsp");
            }
            else
            {
                response.getWriter().write("以上信息不能为空");
            }
        }
        else
        {
            response.getWriter().write("请采用正确方式访问");
        }
        
    }

    
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        
        doGet(request, response);
    }

}
<%@ 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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
恭喜你注册成功
</body>
</html>

原文地址:https://www.cnblogs.com/jskbk/p/5633497.html