• 用SQL Server验证用户名和密码


    用SQL Server验证用户名和密码,从页面输入的用户名和密码与数据库的用户名和密码进行匹配,正确则登入,错误则提醒。

       <form action="index.jsp" method="post" >
      <!--大的div框架开始-->
    <div id="div">
    
        <!--左边div框架开始-->
    <div id="div1">
          <p style="margin-left:30px;"><img src="image/login/vjia.gif"></img></p>
          <div style="350px;height:20px;margin-left:30px;margin-top:-10px">
          <p><hr/></p>
          </div>
          <p style="margin-top:0px;margin-left:30px"><img src="image/red_btn.gif"></img></p>
          <p style="margin-top:-35px;margin-left:40px;color:#fff;font-size:12px;align:center">Vjia用户</p>
    
          <p style="margin-top:-28px;margin-left:110px"><img src="image/btn_long.gif"></img></p>
          <p style="margin-top:-35px;margin-left:120px;font-size:12px">Vancl用户</p>
          
      <div style="350px;height:20px;margin-left:30px;margin-top:-8px">
          <p><hr/></p>
          </div>
          
          <p style="margin-left:60px">用户名:<input type="text" name="userName"></p>
          <p style="margin-left:75px">密码:<input type="password" name="password"></p>
    
          <p style="margin-left:150px;margin-top:10px"><input type="submit" value="" style="65px;height:26px;background:url(image/tu2.gif)"></p>
    
    
    
          <p style="margin-left:30px;margin-top:30px;margin-right:80px">使用合作伙伴账号登入Vjia:<img src="image/account_qq.gif"></img></p>
    
          <p style="margin-left:30px;margin-top:0px;color:red;font-weight:bold">温馨提示:</p>
    
          <p style="text-indent:3em;font-size:14px">如果还未注册VJIA用户,您可以使用VANCL用户名进行登录,登录后系统会自动为您注册一个与VANCL账户相关联的VJIA账户。账户关联后您可共享VANCL的会员积分和消费金额。</p>
          <p style="margin-top:30px;margin-left:100px">有任何疑问请点击<font style="font-weight:bold">帮助中心</font><font style="font-weight:bold">联系客服</font></p>
    </div>
    </form>
    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
    <%@page import="java.sql.Connection"%>
    <%@page import="java.sql.PreparedStatement"%>
    <%@page import="java.sql.ResultSet"%>
    <%@page import="jdbc.sqlServer"%>
    
    <%
       String userName = request.getParameter("userName");
       userName = new String(userName.getBytes("ISO-8859-1"),"utf-8");
       String password = request.getParameter("password");
    
             //引用连接数据库方法
           sqlServer sq=new sqlServer();
           //得到数据库连接
           Connection con = sq.getConnection();
           //编写sql语句
           String sql="select * from Admin where userName=? and password=? ";      
           //得到数据库操作对象
               PreparedStatement st=null;
             st =con.prepareStatement(sql);
             st.setString(1,userName);
               st.setString(2,password);
           
           //得到结果集
               ResultSet rs=null;
               rs=st.executeQuery();
               if(rs.next()){
               session.setAttribute("url",userName);
      
            %>
                  <script type="text/javascript">
                    alert("登入成功");
                    location="jieHe.jsp";
                </script>
              <%
         
           
     }else{
          %>
                  <script type="text/javascript">
                    alert("请先注册,后登入");
                    location="doLog.jsp";
                </script>
              <%
    
     }
           //释放资源
         sq.ShiFang(rs,st,con); 
           
       
     %>
         
        
  • 相关阅读:
    fd_set 用法
    初步认识迭代服务器和并发服务器
    慢系统调用与信号中断
    nigix以及相关
    IO多路复用的几种实现机制的分析
    伪终端
    linux非阻塞的socket EAGAIN的错误处理
    从输入 URL 到页面加载完成的过程中都发生了什么事情?
    7.9 函数的定义
    7.8 文件操作
  • 原文地址:https://www.cnblogs.com/wlx520/p/4501665.html
Copyright © 2020-2023  润新知