您现在的位置:计算机技术学习网 > 技术中心 > WEB编程 > JSP >

JSP登录验证功能的实现

来源:网络 责任编辑:栏目编辑 发表时间:2013-07-01 05:32 点击:

静态的登录界面的设计login.htm,代码如下:

<html>
<head>
    <title>系统登录</title>
    <style type="text/css">...
<!--
.style1 {...}{
    font-size: 18px;
    font-weight: bold;
}
.style2 {...}{font-size: 24px}
.style5 {...}{font-size: 16px}
-->
    </style>
</head>
<body bgcolor="papayawhip"  width="300" height="300">
    <center>
    <table border="2" bordercolor="black" bgcolor="lightgreen">
    <tbody>
    <tr>
    <td><div align="center" class="style1 style2">系 统 登 录
      </div></td>
    </tr>
    <form action="login.jsp(SUN企业级应用的首选)" method="post">
        <tr>
        <td height="28"><span class="style5">用户名</span>            <input type="text" name="uid" maxlength="20" style="width:150"></td></tr><br>
        <tr>
        <td><span class="style5">密&nbsp;&nbsp;码</span>        <input type="password" name="upwd" maxlength="20" style="width:150"></td></tr><br>
        <center>
        <tr><td><div align="center">
              <input type="submit" value="登录" >&nbsp;&nbsp;
              <input type="reset" value="取消">
          </div></td></tr>
        </center>
    </form>
   
    </tbody>
    </table>
    </center>
</body>
</html>
将登录用户输入的信息提交到login.jsp(SUN企业级应用的首选)页面机型处理,这里为了方便,不执行数据库的访问操作,直接使用sky2098作为登录用户名和密码,但在实际中是要从数据库中读取的,该jsp(SUN企业级应用的首选)页面代码实现如下:

<%...@ page contentType="text/html;charset=GB2312"%>
<%...
    if(request.getParameter("uid").equals("sky2098")&&request.getParameter("upwd").equals("sky2098")){
        session.setAttribute("login","ok");
        session.setMaxInactiveInterval(-1);
%>
<jsp(SUN企业级应用的首选):forward page="main.jsp(SUN企业级应用的首选)"/>
<%...
    }else{
            out.println("用户名或密码输入错误!");
}
%>

如果登录成功,则设定login的值为ok,提交到下一步验证页面,则进入main.jsp(SUN企业级应用的首选)页面,否则,如果输入的用户名和密码不合法就打印错误信息,main.jsp(SUN企业级应用的首选)页面代码如下:

    相关新闻>>

      发表评论
      请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
      用户名: 验证码:点击我更换图片
      最新评论 更多>>

      推荐热点

      • JSP与Servlet
      • 自己动手写MiniBBS系列(基本篇)之用户登录
      • JSP取当前日期
      • JDBC 入门(一)
      • 打开一个jsp页面默认查询所有数据,调用action
      • 使用JSP标签库验证用户的输入(2)完
      • WIN98/2000下的jsp服务器
      • 自定义JSP标签(tag)浅议
      • Struts学习傻瓜式入门篇
      网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
      Copyright © 2008-2015 计算机技术学习交流网. 版权所有

      豫ICP备11007008号-1