一、界面展示

二、登录成功显示

三、代码

html

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4 <meta charset="UTF-8">
 5 <title>Insert title here</title>
 6    <link rel="stylesheet" type="text/css" href="NewStyle.css">
 7 </head>
 8 <body>
 9 <div class="content">
10 <h2 >用户登录</h2>
11 <div class="box">
12 <form action="/load/TestServlet" id="loading" method="post">
13 <input type="text" placeholder="用户名" id="name" name="username"><br><br>
14 <input type="password" placeholder="密码" id="pwd" name="password"><br><br>
15 <button type="submit" id="btn">登录</button>
16 </form>
17 </div>
18 </div>
19 </body>
20 </html>

View Code

css

 1 @charset "UTF-8";
 2 .content{
 3     width:400px;
 4     height:280px;
 5     margin-left:35%;
 6     margin-top:100px;
 7     background-color:#ffd0d0;
 8     text-align:center;
 9     padding-top:30px;
10 }
11 .box{
12     width:200px;
13     height:200px;
14     margin-top:50px;
15     text-align:center;
16     margin-left:25%;
17 }

View Code

servlet

 1 package load;
 2
 3 import java.io.IOException;
 4 import java.io.PrintWriter;
 5
 6 import javax.servlet.ServletException;
 7 import javax.servlet.annotation.WebServlet;
 8 import javax.servlet.http.HttpServlet;
 9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
11
12 /**
13  * Servlet implementation class TestServlet
14  */
15 @WebServlet("/TestServlet")
16 public class TestServlet extends HttpServlet {
17     private static final long serialVersionUID = 1L;
18
19     /**
20      * @see HttpServlet#HttpServlet()
21      */
22     public TestServlet() {
23         super();
24         // TODO Auto-generated constructor stub
25     }
26
27     /**
28      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
29      */
30     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
31         // TODO Auto-generated method stub
32         //response.getWriter().append("Served at: ").append(request.getContextPath());
33         request.setCharacterEncoding("UTF-8");
34         response.setContentType("text/html;charset=utf-8");
35         String uname=request.getParameter("username");
36         String pwd=request.getParameter("password");
37         if(("tom").equals(uname)&&("123").equals(pwd)) {
38             //response.sendRedirect("/load/Welcome.html");
39             PrintWriter out=response.getWriter();
40             out.write("用户名是:"+uname+",密码是:"+pwd);
41         }
42         else {
43             response.sendRedirect("/load/NewFile.html");
44         }
45     }
46
47     /**
48      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
49      */
50     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
51         // TODO Auto-generated method stub
52         doGet(request, response);
53
54     }
55
56 }

View Code

总结:总结来说做的比较简单,还需要深入的了解。

转载于:https://www.cnblogs.com/funnn24/p/10585503.html

用SERVLET进行用户名和密码验证相关推荐

  1. apache用户名和密码验证

    一.Apache服务器已经内置用户验证机制 大家只要适当的加以设置,便可以控制网站的某些部分要用户验证.前期准备,必须已经安装apache,如果还没安装,或者对安装很模糊的话,      第1步:我们 ...

  2. c语言如何判断密码不同字符,C语言从文本文档读取字符串(用户名和密码验证)...

    简单的从txt文档中获取用户名和密码并验证 #include #include int recog_pwd(char name[20],char pwd[20]); void main() { int ...

  3. android 客户端使用service处理用户名和密码验证,android透过webservice验证用户

    当前位置:我的异常网» Web前端 » android透过webservice验证用户 android透过webservice验证用户 www.myexceptions.net  网友分享于:2015 ...

  4. Access 窗体实现用户名及密码验证登录

    登录界面如下 组合框名称为:借书证号 文本密码框名称为:密码 表:借书证 进入VBA编程的方式 设计视图中右键登录按钮--属性--事件 在VBA编程器中写代码 Private Sub 登录_Click ...

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

    链接:https://pan.baidu.com/s/1zi7Vs9ghP_T2CVkKOL7-4w 提取码:iral 在控制台上获取并显示获取内容 转载于:https://www.cnblogs.c ...

  6. perl 操作 timesten 数据库 带用户名和密码验证

    此处借用 ODBC 来操作timesten 数据库,前提安装tt数据库 #!/usr/bin/perl use warnings; use DBI; use DBD::ODBC; use strict ...

  7. perl 操作redis 数据库 带用户名和密码验证,选择数据库0.1.2

    host_port=>'127.0.0.1:6379,127.0.0.1:6377', dbcollections=>'rediscon111', password=>'rooti' ...

  8. 太实用了!自己动手写软件——邮件用户名密码验证

    我们计划实现的弱口令破解软件一共支持如下四类协议的解析: 数据库类--MySQL.Oracle和SQL server 邮件类--IMAP.POP3和SMTP 文件传输类--FTP 运维类--SSH 数 ...

  9. H3C交换机配置本地和远程登录用户名和密码

    进入用户界面视图 [SwitchA]user-interface vty 0 4 设置认证方式为密码验证方式 [SwitchA-ui-vty0-4]authentication-mode passwo ...

最新文章

  1. Facebook首席工程负责人胡鲁辉:数字化2.0的理念、架构与业务模型丨鲸犀峰会
  2. 记录一个ansible高级用法与shell结合
  3. Java中的Atomic包
  4. win7中安装vs2008的升级成正式版的方法
  5. mysql 主从 仅备份从库_MySQL主从复制 - 从数据库备份数据库
  6. 扩展可以支持枚举类型的DorpDownList控件
  7. Inferred type 'S' for type parameter 'S' is not within its bound;
  8. jsp购物车系统01
  9. md5修改器v1.0
  10. 音视频即时通讯开发平台
  11. 设计FMEA步骤五:风险分析
  12. python遍历文件夹循环处理图片
  13. 九宫怎么排列和使用_风水知识:三元九运与九宫飞星排布方法!
  14. Excel图表制作(二):动态图表制作
  15. Drawable的setBounds方法
  16. 文心一格x网易「EVE宇宙航母预研」主题AI绘画大赛即将开启!
  17. GooglePlay区分推荐来源
  18. 金蝶kis记账王自定义账套选项的方法
  19. Open3d从RGBD生成点云、mesh
  20. 注册测绘师20180301-CNSS

热门文章

  1. 马化腾很受伤 后果很严重
  2. Linux下安装Tomcat
  3. cURL error 60: SSL certificate problem: unable to get local issuer certifica 解决
  4. H.264---CABAC---基础---二进制算术编码
  5. codefirst数据库迁移
  6. 数据结构与算法之贪心算法 C++实现
  7. Linux (四)其他一些服务的实现
  8. (转) 理解WebKit和Chromium
  9. 用STL给C++充电:第一部分
  10. Google是否会成为下一个微软?