用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="width: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="width: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="width: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); 
       
   
 %>
     
    

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM