Users.java

package com.po;

public class Users {
private String username;
private String password; public Users()
{ } public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
}
}

LoginServlet.java

处理post请求 + 判定用户 + 页面跳转

 package com.servlet;

 import java.io.IOException;

 import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import com.po.Users;
@WebServlet(value="/servlet/LoginServlet")
public class LoginServlet extends HttpServlet{ /**
* Constructor of the object.
*/
public LoginServlet() {
super();
} /**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
} /**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { doPost(request,response);
} /**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { Users u = new Users();
String username = request.getParameter("username");
String password = request.getParameter("password");
u.setUsername(username);
u.setPassword(password); if(u.getUsername().equals("admin")&&u.getPassword().equals("admin"))
{
response.sendRedirect(request.getContextPath()+"/login_success.jsp");
}
else
{
response.sendRedirect(request.getContextPath()+"/login_failure.jsp");
}
} /**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}

Serervlet | 慕课课程实战 | 编写登录逻辑的更多相关文章

  1. ABP+AdminLTE+Bootstrap Table权限管理系统第七节--登录逻辑及abp封装的Javascript函数库

    经过前几节,我们已经解决数据库,模型,DTO,控制器和注入等问题.那么再来看一下登录逻辑.这里算是前面几节的一个初次试水. 首先我们数据库已经有的相应的数据. 模型和DTO已经建好,所以我们直接在服务 ...

  2. ABP+AdminLTE+Bootstrap Table权限管理系统第七节--登录逻辑及几种abp封装的Javascript函数库

    返回总目录:ABP+AdminLTE+Bootstrap Table权限管理系统一期         简介 经过前几节,我们已经解决数据库,模型,DTO,控制器和注入等问题.那么再来看一下登录逻辑.这 ...

  3. 0.1---selenium+java自动化测试进阶02----项目实战之登录代码重构

    一.测试登录功能实现 以慕课网的登录为例,分析登录的功能需求,编写测试用例,找到要定位的元素以及需要的操作,编写登录功能的测试代码.代码实现如下: public static void main(St ...

  4. SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 后端篇(五): 数据表设计、使用 jwt、redis、sms 工具类完善注册登录逻辑

    (1) 相关博文地址: SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 前端篇(一):搭建基本环境:https://www.cnblogs.com/l-y-h/p ...

  5. Django 小实例S1 简易学生选课管理系统 6 实现登录逻辑

    Django 小实例S1 简易学生选课管理系统 第6节--实现登录逻辑 点击查看教程总目录 作者自我介绍:b站小UP主,时常直播编程+红警三,python1对1辅导老师. 1 业务逻辑 本教程第四节里 ...

  6. Dapr 与 NestJs ,实战编写一个 Pub & Sub 装饰器

    Dapr 是一个可移植的.事件驱动的运行时,它使任何开发人员能够轻松构建出弹性的.无状态和有状态的应用程序,并可运行在云平台或边缘计算中,它同时也支持多种编程语言和开发框架.Dapr 确保开发人员专注 ...

  7. android内部培训视频_第五节(1)_OA实战之登录界面

    第五节(1):OA实战之登录界面  一.登录界面布局 1.背景图片 2.文本框 3.checkbox 4.按钮 暂未实现点击切换图片效果 <RelativeLayout xmlns:androi ...

  8. 网站实现微信登录之回调函数中登录逻辑的处理--基于yii2开发的描述

    上一篇文章网站实现微信登录之嵌入二维码中描述了如何在自己的登录页面内嵌入登录二维码,今天的这篇文章主要是描述下在扫码成功之后微信重定向回网站后登录逻辑的处理,其实也就是验证身份信息,授权用户登录的逻辑 ...

  9. 关于python怎样编写登录接口

    把今天的成果展示下,关于怎么用python编写登录接口, 要求是   1.输入用户名和密码 2.输错三次密码就锁定用户 3.认证成功后输出欢迎信息 账号文件内容如下: sanjiang sanjian ...

随机推荐

  1. duilib查看过的资料整理

    1.duilib中各个类的简单介绍 2.源码分析 3.各个控件可以设置的属性 4.duilib的消息流程处理 5.工程编译入门 6.MFC中混合使用duilib制作界面 7.从Win32窗口到duil ...

  2. Algorithm: Euclid's algorithm of finding GCD

    寻找最大公约数方法 代码如下: int gcd (int a, int b) { return b ? gcd (b, a % b) : a; } 应用:求最小公倍数 代码如下: int lcm (i ...

  3. 关于MySQL的information_schema库简单介绍及实际应用

    本文简介 写本文主要是围绕下面几点进行的. 1.information_schema数据库到底是做什么用的? 2.执行alter table 表名 modify column 字段名 类型 这个sql ...

  4. uboot显示logo的时候发现颜色偏黄【学习笔记】

    平台信息:内核:linux3.0.68 系统:android6.0平台:rk3288 将一张图片烧录进logo分区,发现在uboot读取这张图片并显示的时候发现颜色偏黄,解决办法,在烧录bmp图片的时 ...

  5. (转)定制findbugs规则

    转载自http://www.51testing.com/html/97/13997-211893.html 这类文章极少,字节码操作需要对becl库及jvm字节码操作有一定常识.参考: http:// ...

  6. Ansible 动态获取主机列表

    参考文献: http://www.linuxidc.com/Linux/2016-12/138111.htm 附加 这个 include_vars 变量,可以 动态分别环境或者其他条件- hosts: ...

  7. poj3181【Dollar Dayz】

    做完这道题,心里五味陈杂,明明是最水的一道题,我却做了最长的时间. 题意是求用1-k的和表示n的方案数. 显然是个计数dp,但我不会.思考半小时未果. 然后找尹鹏哲,他给我讲了个错的dp方程,结果调试 ...

  8. Thrift之代码生成器Compiler原理及源码详细解析1

    我的新浪微博:http://weibo.com/freshairbrucewoo. 欢迎大家相互交流,共同提高技术. 又很久没有写博客了,最近忙着研究GlusterFS,本来周末打算写几篇博客的,但是 ...

  9. POI实现DOC/DOCX转HTML

    1.使用HWPF处理DOC public class DocToHtml { private static final String encoding = "UTF-8"; pub ...

  10. springboot开启远程调试

    远程调试maven设置 The run goal forks a process for the boot application. It is possible to specify jvm arg ...