<!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页面登录验证的更多相关文章

  1. 搭建开发框架Express,实现Web网站登录验证

    NodeJS学习笔记(一)——搭建开发框架Express,实现Web网站登录验证   JS是脚本语言,脚本语言都需要一个解析器才能运行.对于写在HTML页面里的JS,浏览器充当了解析器的角色.而对于需 ...

  2. Java Web Filter登录验证

    初做网站需要登录验证,转自 :http://blog.csdn.net/daguanjia11/article/details/48995789 Filter: Filter是服务器端的组件,用来过滤 ...

  3. NodeJS学习笔记(一)——搭建开发框架Express,实现Web网站登录验证

    JS是脚本语言,脚本语言都需要一个解析器才能运行.对于写在HTML页面里的JS,浏览器充当了解析器的角色.而对于需要独立运行的JS,NodeJS就是一个解析器.每一种解析器都是一个运行环境,不但允许J ...

  4. 【原】web页面登陆验证

    using Itcast.Mall.Model; using System; using System.Collections.Generic; using System.Linq; using Sy ...

  5. Filter登录验证过滤器(全局)

    通过Filter来定义一个登录验证过滤器,这是就不需要在每一个JSP页面添加判断用户合法性的代码了. 以下示例中包含了5个文件,一个是登录表单LoginForm.jsp,一个是登录判断页LoginCo ...

  6. 由前端登录验证,页面跳转,携带headers token引发的思考和尝试

    目录 1 前言 2 我的实现方式与存在的问题 3 我想到的解决方案 3.1 前端跳转时携带headers{'token': token} 不就行了(经验证不可行) 3.2 前端跳转封装请求,携带hea ...

  7. MVC前台页面做登录验证

    最近接触了一个电商平台的前台页面,需要做一个登录验证,具体情况是:当用户想要看自己的订单.积分等等信息,就需要用户登录之后才能查询,那么在MVC项目中我们应该怎么做这个前台的验证呢? 1.我在Cont ...

  8. tornado web高级开发项目之抽屉官网的页面登陆验证、form验证、点赞、评论、文章分页处理、发送邮箱验证码、登陆验证码、注册、发布文章、上传图片

    本博文将一步步带领你实现抽屉官网的各种功能:包括登陆.注册.发送邮箱验证码.登陆验证码.页面登陆验证.发布文章.上传图片.form验证.点赞.评论.文章分页处理以及基于tornado的后端和ajax的 ...

  9. 实现手机扫描二维码页面登录,类似web微信-第四篇,服务器端

    转自:http://blog.csdn.net/otangba/article/details/8273952 终于到了服务器端,第三篇的手机客户端如果已经下载了的话,没有服务器是不能正常运行的. 服 ...

随机推荐

  1. margin/padding百分比值的计算

    1.百分比介绍 一般元素的宽度用百分比值表示时,元素的总宽度包括外边距取决于父元素的width,这样可能得到"流式"页面,即元素的外边距会扩大或缩小以适应父元素的实际大小.如果对这 ...

  2. Jmeter 中文乱码解决方案

    中文乱码一直都是比较让人棘手的问题,我们在使用Jmeter的过程中,也会遇到中文乱码问题,我查阅网上的资料解决方案都大同小异,而且不够全面或者不够详细,经过潜心研究终有所得,现在我将jmeter乱码解 ...

  3. jsc2019_qualD Classified

    题目大意 给你一个有n个点的完全图 求一种方案是的给边染色后任何一点不能沿一种颜色的边走奇数条边回到这个点 要求颜色数最少 分析 考场上输出格式打错见祖宗... 我们每次找一个最大二分图将其染一个新颜 ...

  4. WingIIDE 6的licese破解方法(支持python3)

    (1) 安装WingIDE成功后启动,激活时输入license id CN123-12345-12345-12345 (2)点击Continue后弹框,拷贝框中的request code(将其放入脚本 ...

  5. 【SQL SERVER】常见问题

    [账户] 偷懒默认安装了全部默认功能到虚拟服务器上,所以并没有设置sa账户的过程,自然只能从windows身份验证进入数据库.于是还得自己来为sa账户添加登陆权限. 步骤如下: 1. windows身 ...

  6. Python 操作 mongodb 亿级数据量使用 Bloomfilter 高效率判断唯一性 例子

    工作需要使用 python 处理 mongodb 数据库两亿数据量去重复,需要在大数据量下快速判断数据是否存在 参考资料:https://segmentfault.com/q/101000000061 ...

  7. Postman 测试Xfire webservice

    权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/u013177381/article/det ...

  8. MySQL点滴记录

    1.查询所用引擎 show engines;

  9. 关于VMware中的几个网络模式

    直接参考别人的: 写的已经很细致了: http://blog.csdn.net/yaoyaowugui/article/details/7422388 关键是看别人的几张图

  10. Spring学习(七)--Spring MVC的高级技术

    一.Spring MVC配置的替代方案 我们已经了解如何通过AbstractAnnotationConfigDispatcherServlet- Initializer快速搭建了Spring MVC环 ...