使用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="zhuce" method="post">
帐号:<input type="text" name="username">
密码:<input type="password" name="password">
重复密码:<input type="password" name="repassword">
<br>
<input type="submit" value="注册">
</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 zhuce extends HttpServlet {
    private static final long serialVersionUID = 1L;
   
    public zhuce() {
        super();
       
    }

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

        String zh = request.getParameter("username");
        String mm = request.getParameter("password");
        String remm = request.getParameter("repassword");
        response.setContentType("text/html;charset=GB2312");    
        if(zh!=null&&mm!=null&&remm!=null)
        {
            if(!zh.equals(""))
            {
               if(mm.equals(remm))
              {
                response.getWriter().write("注册成功!");
              }
              else
              {
                
                response.getWriter().write("两次密码输入不同,请检查后重新输入!");
                response.setHeader("refresh", "3;URL=zhuce.jsp");
              }
            }
            else
            {
                response.getWriter().write("用户名不能为空字符串");
                response.setHeader("refresh", "3;URL=zhuce.jsp");
            }
         }
        
    }

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

}

posted @ 2016-07-01 22:12  凌零聆  阅读(1509)  评论(0编辑  收藏  举报