zoukankan      html  css  js  c++  java
  • 使用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);
        }
    
    }

  • 相关阅读:
    动态规划(最长公共序列,最长上升序列)
    滴滴笔试--算术转移(20190827)
    线段树和树状数组
    pair和list学习
    数据结构--树(建立、遍历)
    tmux常用命令与快捷键
    机器学习实战-逻辑回归
    字符流中第一个重复的字符
    机器学习实战-朴素贝叶斯
    Python第三方库
  • 原文地址:https://www.cnblogs.com/wenwen123/p/5634376.html
Copyright © 2011-2022 走看看