博客
关于我
JSP内置对象---一个小项目(实现用户的登录 (不使用数据库))
阅读量:270 次
发布时间:2019-03-01

本文共 2155 字,大约阅读时间需要 7 分钟。

这里写图片描述

最终效果:
用户登录
登录成功
登录失败
下面只给出实现功能的JSP代码
Login.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"    pageEncoding="utf-8"%>        
imooc - Login

dologin.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"    pageEncoding="utf-8"%><%    String path = request.getContextPath();    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";    String username = "";    String password = "";    request.setCharacterEncoding("utf-8");    username = request.getParameter("username");    password = request.getParameter("password");    if("admin".equals(username)&&"admin".equals(password)){        request.getRequestDispatcher("login_success.jsp").forward(request, response);        session.setAttribute("username", username);    } else {        response.sendRedirect("login_failure.jsp");    }%>

login_success.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"    pageEncoding="utf-8"%>        
imooc - Login
<% String loginUser = ""; if(session.getAttribute("username") != null){ loginUser = session.getAttribute("username").toString(); } %>

欢迎您 <%=loginUser%> 登录成功

login_failure.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"    pageEncoding="utf-8"%>        
imooc - Login
登录失败,请检查用户名密码;
返回登陆页面
你可能感兴趣的文章
mysql-group_concat
查看>>
MySQL-redo日志
查看>>
MySQL-【1】配置
查看>>
MySQL-【4】基本操作
查看>>
Mysql-丢失更新
查看>>
Mysql-事务阻塞
查看>>
Mysql-存储引擎
查看>>
mysql-开启慢查询&所有操作记录日志
查看>>
MySQL-数据目录
查看>>
MySQL-数据页的结构
查看>>
MySQL-架构篇
查看>>
MySQL-索引的分类(聚簇索引、二级索引、联合索引)
查看>>
Mysql-触发器及创建触发器失败原因
查看>>
MySQL-连接
查看>>
mysql-递归查询(二)
查看>>
MySQL5.1安装
查看>>
mysql5.5和5.6版本间的坑
查看>>
mysql5.5最简安装教程
查看>>
mysql5.6 TIME,DATETIME,TIMESTAMP
查看>>
mysql5.6.21重置数据库的root密码
查看>>