zoukankan      html  css  js  c++  java
  • 登录连接数据库

    login

    <%@ page import="java.sql.*" 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>
        <center>
            <h1 style="color:red">登录</h1>
                <form id="indexform" name="indexForm" action="logincheck.jsp" method="post">
                    <table border="0">
                        <tr>
                            <td>账号:</td>
                            <td><input type="text" name="username"></td>
                        </tr>
                        <tr>
                            <td>密码:</td>
                            <td><input type="password" name="password">
                            </td>
                        </tr>
                    </table>
                <br>
                    <input type="submit" value="登录" style="color:#BC8F8F">
                </form>
        </center>
    </body>
    </html>

    logincheck
    <%@ page import="java.sql.*" 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>Insert title here</title>
    </head>
    <body>
    <jsp:useBean id="db" class="Bean.DBBean" scope="page"/>
    <%
        request.setCharacterEncoding("UTF-8");
        String username=(String)request.getParameter("username");
        String password=(String)request.getParameter("password");//取出login.jsp的值
        
        
        //下面是数据库操作 *代表所有值
        String sql="select * from lhT where username="+"'"+username+"'";//定义一个查询语句
        ResultSet rs=db.executeQuery(sql);//运行上面的语句
        if(rs.next())
        {
            /* if(password.equals(rs.getString(2)))
            {
                
            } */
            if(password.equals(rs.getObject("password"))){
                response.sendRedirect("loginsuccess.jsp");
            }
            else{
                out.print("<script language='javaScript'> alert('密码错误');</script>");
                response.setHeader("refresh", "0;url=login.jsp");
            }
        }
        else 
        {
            out.print("<script language='javaScript'> alert('请输入用户名——else');</script>");
            response.setHeader("refresh", "0;url=login.jsp");
        }
        
    %>
    </body>
    </html>

    loginsuccess.jsp

    <%@ page import="java.sql.*" 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=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <h1>登录成功 </h1>
    </body>
    </html>
    复制代码


  • 相关阅读:
    27、深入理解计算机系统笔记,网络编程
    29、深入理解计算机系统笔记,并发编程(concurrent)(1)
    28、深入理解计算机系统笔记,Web服务器简介
    18、Linux下编程风格
    26、深入理解计算机系统笔记,系统级I/O
    32、深入理解计算机系统笔记,Unix下处理错误的风格
    31、深入理解计算机系统笔记,并发编程(concurrent)(3)
    19、Linux编码规范
    ASP.NET 中 DropDownList+DataList(数据列表)的使用前台绑定
    ASP.NET中 DetailsView(详细视图)的使用前台绑定
  • 原文地址:https://www.cnblogs.com/frankzone/p/7695680.html
Copyright © 2011-2022 走看看