zoukankan      html  css  js  c++  java
  • 学习练习 使用Servlet实现用户注册功能

    package com.hanqi.www;
    
    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 Test111 extends HttpServlet {
        private static final long serialVersionUID = 1L;
           
       
        public Test111() {
            super();
            
        }
    
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            
            response.setContentType("text/html");
            response.setCharacterEncoding("UTF-8");
            
            String us = request.getParameter("username");
            String pw = request.getParameter("password");
            String pw1 = request.getParameter("password1");
            //判断是否正确接收
                    if(us != null && pw != null && pw1 != null)
                    {
                        if(!us.equals(""))
                        {
                    
                        if(pw.equals(pw1))
                        {
                            //记录用户信息
                            
                            //跳转到系统主页面
                            response.sendRedirect("Main.jsp");
                            
                        }
                        else
                        {
                            //否则就提示登录错误
                            response.getWriter().write("请输入相同的密码");
                        }
                        }
                        else
                        {
                            response.getWriter().write("帐号或密码不能为空字符串");
                        }
                    }
                    else
                    {
                        response.getWriter().write("请正确输入您的信息");
                    }
                
            response.getWriter().append("Served at: ").append(request.getContextPath());
        }
    
        
        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>
    <%@ 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>
    注册页面
    <br>
    <%
    //销毁session
    session.invalidate();
    %>
    
    <form action="testpw" method = "get">
    账户:<input type="text"name = "username"><br>
    密码:<input type="password"name = "password"><br>
    确认密码:<input type="password"name = "password1"><br>
    <input type="submit" value="注册">
    </form>
    </body>
    </html>

  • 相关阅读:
    [MCM] PSO粒子群算法解决TSP问题
    [MCM] 2017研究生数学建模竞赛A题 3架飞机 TSP 求总路径最小
    [tool] AI视频翻译 解决英文视频字幕问题(类似youtube自动生成字幕)
    使用vsnprintf后链接错误及解决方法
    Linux Shell编程
    如何把va_list可变参数传送到下一级函数中(如传送到printf)
    ubuntu phone/touch的源码从哪里下载?
    The Native POSIX Thread Library for Linux
    Linux内核头文件与内核与库的关系
    Buildroot阅读笔记
  • 原文地址:https://www.cnblogs.com/zhoudi/p/5633227.html
Copyright © 2011-2022 走看看