用servlet进行用户名和密码校验

Posted yangss-myblog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用servlet进行用户名和密码校验相关的知识,希望对你有一定的参考价值。

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>西南石油大学电子邮件系统</title>
        <link rel="stylesheet" type=text/css href="Mystyle.css" />
    </head>
    <body>
        <div class="t">
            <div class="h">
                <div class="logo">
                    <img src="img/login_logo.png"/>
                </div>
                <a target="_blank" class="help">帮助</a>
            </div>
        </div>
        
        <div class="c">
            <div class="box" style="right: 60px;top: 60px;left: auto;" id="box">
                <ul class="tab" id="tab">
                    <li class="current">账号登录</li>
                    <li class="dragbar"></li>
                </ul>
                
                <div class="boxc" id="tab_via_acct">
                    <h3>用户登录</h3>
                    <form>
                    <div class="text_item">
                        <input type="text" class="text" id="user" name="user" style="font-size: 20px;" _autocomplete="off" placeholder="用户名">                                                                            
                    </div>
                    
                            <div>
                                <input type="password" class="text" id="password" _autocomplete="off" name="password" placeholder="密码">        
                            </div>
                            
                            <div class="b1">
                                <span style="float: left;">
                                    <font style="color: red;font-family: ‘宋体‘; clear: both;">学生选择@stu.swpu.edu.cn</font>
                                </span>
                                <span class="blt">
                                    <a style="text-decoration: none;">忘记密码</a>
                                </span>
                            </div>
                            
                            <div class="btnb">
                                <input type="submit" name="submit" class="btn" value="登  录" style="float: right;">
                            </div>
                        </form>
                </div>
                
            </div>
        </div>
        
        <div class="b">西南石油大学</div>
</html>
package com.Swpu.email;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ServletRequest
 */
public class ServletRequest extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private String User;
    private String Password;   
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServletRequest() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.getWriter().append("Served at: ").append(request.getContextPath());
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.setContentType("text/html;charset=UTF-8");
        response.setCharacterEncoding("utf-8");
        PrintWriter out=response.getWriter();
        //获取参数
        User=request.getParameter("user");
        Password=request.getParameter("password");
 
        if(User.equals("tom") && Password.equals("123")) {
            out.print("<h1>登陆成功</h1>");
            out.print("欢迎 : " + User+",您的密码是:"+Password);
        }else if(User==""||Password==""){
            out.print("<h1>用户名或密码不能为空</h1>");
        }else {
            out.print("<h1>用户名或密码错误</h1>");
        }
            out.close();
    }    
}

 技术图片

链接:https://pan.baidu.com/s/1fPl0D_V13PUZOwDCIewM1A
提取码:0xgd
复制这段内容后打开百度网盘手机App,操作更方便哦

以上是关于用servlet进行用户名和密码校验的主要内容,如果未能解决你的问题,请参考以下文章

用servlet进行用户名和密码校验

用servlet进行用户名和密码校验01

用servlet进行用户名和密码校验

用servlet进行用户名和密码校验

用servlet进行用户名和密码校验

用servlet进行用户名和密码校验