用JSP实现WEB页面登录验证
<!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>
<center>
<h2>系统登录</h2>
<form action="login.jsp" method="post">
<input type="text" name="uid" maxlength=8 style="width:150"><br>
<input type="password" name="upwd" maxlength=8 style="width:150"><br>
<input type="submit" value="登录">
<input type="reset" value="取消">
</form>
</center>
</body>
</html>
2.login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="java.sql.* "%>
<!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>
<%
String user_name= request.getParameter("uid");
String pass_word = request.getParameter("upwd");
if(user_name!=null && !user_name.equals("")){
try{
Class.forName("org.gjt.mm.mysql.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/test","test","test");
Statement stmt=(Statement)conn.createStatement();
String sql="select * from account where username='"+user_name+"'";
sql +="and password='"+pass_word+"'";
ResultSet rs=(ResultSet)stmt.executeQuery(sql);
if(rs.next())
{
session.setAttribute("login","ok");
session.setAttribute("uname",user_name);
%>
<jsp:forward page="main.jsp"/>
<%
}else out.println("错误的用户名和密码");
out.println("<a href=index.html>返回</a>");
}catch(Exception ee){ee.printStackTrace();}
}else{
out.println("请先登录");
out.println("<a href=index.html>返回</a>");
}
%>
</body>
</html>
3.main.jsp
<%@ 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>
<%@include file="checkvalid.jsp"%>
欢迎进入本页面,您已经通过了验证,你的用户名是:<%=session.getAttribute("uname") %><p>
<a href=continue.jsp>您可以跳转到后续页面</a>
</body>
</html>
4.checkvalid.jsp
<%@ 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>
<%
if(session.getAttribute("login")==null||!session.getAttribute("login").equals("ok"))
{response.sendRedirect("index.html");}
%>
</body>
</html>
5.continue.jsp
<%@ 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>
<%@include file="checkvalid.jsp"%>
<%=session.getAttribute("uname") %>,欢迎您进入第二个页面!<p>
</body>
</html>
from: http://blog.sina.com.cn/s/blog_4cc54e95010009vh.html
用JSP实现WEB页面登录验证的更多相关文章
- 搭建开发框架Express,实现Web网站登录验证
NodeJS学习笔记(一)——搭建开发框架Express,实现Web网站登录验证 JS是脚本语言,脚本语言都需要一个解析器才能运行.对于写在HTML页面里的JS,浏览器充当了解析器的角色.而对于需 ...
- Java Web Filter登录验证
初做网站需要登录验证,转自 :http://blog.csdn.net/daguanjia11/article/details/48995789 Filter: Filter是服务器端的组件,用来过滤 ...
- NodeJS学习笔记(一)——搭建开发框架Express,实现Web网站登录验证
JS是脚本语言,脚本语言都需要一个解析器才能运行.对于写在HTML页面里的JS,浏览器充当了解析器的角色.而对于需要独立运行的JS,NodeJS就是一个解析器.每一种解析器都是一个运行环境,不但允许J ...
- 【原】web页面登陆验证
using Itcast.Mall.Model; using System; using System.Collections.Generic; using System.Linq; using Sy ...
- Filter登录验证过滤器(全局)
通过Filter来定义一个登录验证过滤器,这是就不需要在每一个JSP页面添加判断用户合法性的代码了. 以下示例中包含了5个文件,一个是登录表单LoginForm.jsp,一个是登录判断页LoginCo ...
- 由前端登录验证,页面跳转,携带headers token引发的思考和尝试
目录 1 前言 2 我的实现方式与存在的问题 3 我想到的解决方案 3.1 前端跳转时携带headers{'token': token} 不就行了(经验证不可行) 3.2 前端跳转封装请求,携带hea ...
- MVC前台页面做登录验证
最近接触了一个电商平台的前台页面,需要做一个登录验证,具体情况是:当用户想要看自己的订单.积分等等信息,就需要用户登录之后才能查询,那么在MVC项目中我们应该怎么做这个前台的验证呢? 1.我在Cont ...
- tornado web高级开发项目之抽屉官网的页面登陆验证、form验证、点赞、评论、文章分页处理、发送邮箱验证码、登陆验证码、注册、发布文章、上传图片
本博文将一步步带领你实现抽屉官网的各种功能:包括登陆.注册.发送邮箱验证码.登陆验证码.页面登陆验证.发布文章.上传图片.form验证.点赞.评论.文章分页处理以及基于tornado的后端和ajax的 ...
- 实现手机扫描二维码页面登录,类似web微信-第四篇,服务器端
转自:http://blog.csdn.net/otangba/article/details/8273952 终于到了服务器端,第三篇的手机客户端如果已经下载了的话,没有服务器是不能正常运行的. 服 ...
随机推荐
- vue定义自定义事件方法、事件传值及事件对象
1.自定义事件 例如v-on:click="run" 或者 @click="run" <template> <div id="app ...
- python中时间戳,datetime 和时间字符串之间得转换
# datetime时间转为字符串def Changestr(datetime1): str1 = datetime1.strftime('%Y-%m-%d %H:%M:%S') retu ...
- 给网页标题添加icon小图标
so easy: 给网页标题添加icon小图标: 直接在html文件的head部分添加下面代码(注意href的路径): <link rel="icon" type=" ...
- python 数字系列-复数的数学运算
复数的数学运算 问题 你写的最新的网络认证方案代码遇到了一个难题,并且你唯一的解决办法就是使用复数空间. 再或者是你仅仅需要使用复数来执行一些计算操作. 解决方案 复数可以用使用函数 complex( ...
- Colourful Rectangle【扫描线】
题目链接 很明显的可以发现是一个扫描线的问题,但是怎么处理区域呢,发现只有三种颜色,也就是最多也就是7种状态,那么我们可以进行一个状态压缩即可. 但是,在向上pushup的时候,存在我们要以子树的状态 ...
- 解决Sql Server服务远程过程调用失败
方法一:修复Sql Server: 修复过程中若遇到:重新启动计算机失败, 1.按下组合键[Win]+[R],调出运行窗口 2.输入“regedit”,在注册表左侧目录栏中找到如下位置:“HKEY_L ...
- Python入门习题8.羊车门问题
例8. 羊车门问题描述:有3扇关闭的门,一扇后停着汽车,另外两扇门后是山羊,主持人知道每扇门后是什么.参赛者首先选择一扇门.在开启它之前,主持人会从另外两扇门中打开一扇门,露出门后的山羊.此时,允许参 ...
- 2019 Multi-University Training Contest 1 - 1009 - String - 贪心
不知道错在哪里. 是要把atop改成stop!两个弄混了.感谢自造样例. #include<bits/stdc++.h> using namespace std; typedef long ...
- poj2385 Apple Catching (线性dp)
题目传送门 Apple Catching Apple Catching Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 154 ...
- centos7 nginx完整支持thinkphp pathinfo模式开启方法
thinkphp运行在linux+nginx,如何开启pathinfo模式,我是完整测试过了,没问题的,在thinkphp配置文件 开启 'URL_MODEL' => 1, 1代 ...