这是未使用DAO的基本登录,就涉及三个页面 Login.jsp--登录; LoginConf.jsp--完成登录校验并跳转; LoginSuccess.jsp--显示登录成功页面。
 
1. Login.jsp
 

<%@page contentType= "text/html;charset=GB2312" %>
<html>
<head><title>欢迎登陆简单系统</title></head>
    <body>
         <center>
         <h1>用户名和密码是固定的</h1>
         <hr>
                <form action= "loginConf.jsp" method= "post">
                <table>
                    <tr><td colspan= "2">用户登录</td></tr>
                    <tr><td>用户名:</td><td><input type= "text" name= "uname"/></td></tr>
                    <tr><td>密         码:</td><td><input type= "text" name= "upassword"/></td></tr>
                    <tr><td colspan= "2"><input type= "submit" value= "登录"/></td></tr>
                    <tr><td colspan= "2"><input type= "reset" value= "重置"/> </td></tr>
                </table>
                </form>
         </center>
    </body>
</html>
 
2. LoginConf.jsp
 
<%@page contentType= "text/html;charset=GB2312" %>
<%@page import= "java.sql.*" %>
<html>
<head><title>欢迎登陆简单系统</title></head>
    <body>
         <center>
         <h1>用户名和密码是固定的</h1>
         <hr>
                 <!--    
                        这是错误代码的测试
                    -->
                    
                    
                     <%
                     //连接MYSQL数据库
                     String driver = "com.mysql.jdbc.Driver";                 // 驱动程序名
                    
                     String url = "jdbc:mysql://localhost/hibernate";         // URL指向要访问的数据库名scutcs                    
                        
                     String user = "root";             // MySQL配置时的用户名
    
                     String password = "36335576";            // MySQL配置时的密码
                     try {    
                        
                        Class.forName(driver);        // 加载驱动程序
                        
                        Connection conn = DriverManager.getConnection(url, user, password);            // 连续数据库
                        if(!conn.isClosed())    
                         System.out.println("Succeeded connecting to the Database!");         //验证是否连接成功
                        
                        Statement statement = conn.createStatement();                             // statement用来执行SQL语句
                        
                        String sql = "select * from Teacher";                                    // 要执行的SQL语句
                        
                        ResultSet rs = statement.executeQuery(sql);             // 结果集
                        System.out.println("-----------------------------------------");
                        System.out.println("执行结果如下所示:");
                        System.out.println("-----------------------------------------");
                        System.out.println(" 学号" + "\t" + " 姓名" + "\t\t" + "性别");
                        System.out.println("-----------------------------------------");
                        String sname = null;
                        while(rs.next()) {
        
                        
                         sname = rs.getString("name");                                                        // 选择sname这列数据
        
                        
                         System.out.println(rs.getInt("id") + "\t" + sname + "\t" + rs.getString("title"));                // 输出结果
                        }
                        rs.close();
                        conn.close();
                     } catch(ClassNotFoundException e) {

                        System.out.println("Sorry,can`t find the Driver!");    
                        e.printStackTrace();

                     } catch(SQLException e) {

                        e.printStackTrace();

                     } catch(Exception e) {

                        e.printStackTrace();

                     }    
                    
                     %>
            
                <%
                        String name = request.getParameter("uname");
                        String pwd    = request.getParameter("upassword");
                 %>
                 <%
                            //判断用户名和密码
                            if("xiaoqiang".equals(name)&&"tuoxie174".equals(pwd)){
                    %>
                            <jsp:forward page="loginSuccess.jsp" />
                    <%}else{ %>
                            <jsp:forward page="loginFailure.jsp" />
                    <%} %>
                    
                    
                    
         </center>
    </body>
</html>
 
3.LoginSuccess.jsp
 
<%@page contentType= "text/html;charset=GB2312" %>
<html>
<head><title>欢迎登陆简单系统</title></head>
    <body>
         <center>
         <h1>用户名和密码是固定的</h1>
         <hr>
         <br/>
         <br />
             <h3> 登录成功</h3>
             <h3>欢迎 <font color= "blue"><%=request.getParameter( "uname") %></font>登录</h3>
                
         </center>
    </body>
</html>