zoukankan      html  css  js  c++  java
  • Java web 6-1用户登录验证

    <%@ 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>登录页面</title>
    </head>
    <body>
    <form action="loginCheck" method="post">
    请输入用户名:<input type="text" name="username"/><br/>
    请输入密码: <input type="password" name="userpwd"/><br/>
    <input type="submit" value="登录"/>
    <input type="reset"/>
    </form>
    </body>
    </html>

    package servlets;
    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 LoginCheckServlet6_1 extends HttpServlet{
    public void doPost(HttpServletRequest request,HttpServletResponse response)
    throws ServletException,IOException{
    String userName=request.getParameter("username");
    String userPwd=request.getParameter("userpwd");
    String info="";
    if(("meng".equals(userName))&&("123456".equals(userPwd))) {
    info="欢迎你"+userName+"! ";
    }else {
    info="用户名或密码不正确!";
    }
    request.setAttribute("outputMessage", info);
    request.getRequestDispatcher("/Info6-1.jsp").forward(request, response);
    }
    }

    <servlet>
    <servlet-name>LoginCheckServlet6_1</servlet-name>
    <servlet-class>servlets.LoginCheckServlet6_1</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>LoginCheckServlet6_1</servlet-name>
    <url-pattern>/loginCheck</url-pattern>
    </servlet-mapping>

    <%@ 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>显示结果页面</title>
    </head>
    <body>
    <%=request.getAttribute("outputMessage") %>
    </body>
    </html>

    运行

    登录成功:

    登录失败:

  • 相关阅读:
    NO6 alias-unalias命令,递归创建目录,如何取消覆盖提示
    NO4 find&mv-&-特殊符号..和.
    NO5 grep-head-tail命令
    linux面试题:删除一个目录下的所有文件,但保留一个指定文件
    NO3 cat-xargs-cp-mv-rm-find命令
    Linux 快速删除已输入的命令
    NO2 pwd-touch-vim-vi-echo-重定向等命令
    NO1 ip-systemctl-fdisk
    SecureCRT:保存输出日志的方法
    WMware workstation 镜像文件
  • 原文地址:https://www.cnblogs.com/meng2/p/7913114.html
Copyright © 2011-2022 走看看