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="ZhucServlet" method="post">
    用户名<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>
    package com.hanqi.web;
    
    import java.io.IOException;
    import java.io.PrintWriter;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.Cookie;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    
    
    public class ZhucServlet extends HttpServlet {
        private static final long serialVersionUID = 1L;
           
      
        public ZhucServlet() {
            super();
            
        }
    
        
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType("text/html");
            response.setCharacterEncoding("UTF-8");
            String un=request.getParameter("username");
            String pw=request.getParameter("password");
            String pw1=request.getParameter("password1");
            
            if(un!=null&&pw!=null)
            {
                if(pw!=""&&un!="")
                {
                if(pw.equals(pw1))
                {
                    String n=new String(un.getBytes("ISO-8859-1"),"UTF-8");
                    response.getWriter().write(n+",恭喜注册成功");
                }
                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);
        }
    
    }

  • 相关阅读:
    Spring Boot 启动(二) Environment 加载
    Spring Boot 启动(一) SpringApplication 分析
    Java 正则表达式之捕获组
    kylin 系列(一)安装部署
    CDH 安装
    JVM 字节码(四)静态方法、构造代码、this 以及 synchronized 关键字
    JVM 字节码(三)异常在字节码中的处理(catch 和 throws)
    JVM 字节码(二)方法表详解
    JVM 字节码(一)字节码规范
    Hadoop 系列(三)Java API
  • 原文地址:https://www.cnblogs.com/wallan/p/5634754.html
Copyright © 2011-2022 走看看