zoukankan      html  css  js  c++  java
  • JSP第六周作业

    <%@ page 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>
            <style type="text/css">
                body{
                    background-color: azure;
                }
                form{
                    position: fixed;
                    top: 250px;
                    left: 650px;
                    background-color: #ADD8E6;
                    border-radius: 5px;
                }
                div{
                    font-size: 22px;
                    margin-top: 20px;
                    padding-left: 40px;
                }
                input{
                     200px;
                    height: 20px;
                    border-radius: 5px;
                }
                #tj{
                     80px;
                    height: 30px;
            
                    margin-left: 140px;
                        border-radius: 5px;
                        font-size: 16px;
                        margin-bottom: 20px;
                }
            </style>
            
    </head>
    <body>
        <form action="/school/Login.jsp" method="post">
                    <div>账 号:&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="username"></div>
                    <div>密 码:&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="password"></div>
                    <div>验 证 码:<input type="text" name = "yanzhengma"> <img   src="getcode" alt="看不清,换一张" onclick="change(this)"/></div>
                    <div><input type="submit" id="tj" value="登录" ></div>
                </form>
    
    </body>
    <script type="text/javascript">
        function  change(img) {
            img.src = "getcode?"+new Date().getTime();
            
        }
    </script>
    </html>
    复制代码
    复制代码
    <%@page import="java.sql.ResultSet"%>
    <%@page import="java.sql.PreparedStatement"%>
    <%@page import="java.sql.DriverManager"%>
    <%@page import="java.sql.Connection"%>
    <%@ page language="java" contentType="text/html; charset=utf-8"
        pageEncoding="utf-8"
        import=" javax.servlet.http.HttpSession"
        %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <%
    request.setCharacterEncoding("UTF-8");
    response.setContentType("text/html;charset=utf-8");
    response.setCharacterEncoding("UTF-8");
     HttpSession s = request.getSession();
    
     String username = request.getParameter("username");
     String password1 = request.getParameter("password");
         Class clazz = Class.forName("com.mysql.jdbc.Driver");
        // 2.提供另外三个连接的基本信息
        String url = "jdbc:mysql://localhost:3306/school";
        String user = "root";
        String password = "root";
        Connection conn = DriverManager.getConnection(url, user, password);
        PreparedStatement ps = conn.prepareStatement("select uname,upwd from user where uname = ? and upwd = ?");
        ps.setString(1, username);
        ps.setString(2, password1);
        ResultSet rs = ps.executeQuery();
        if(rs.next()){
             session.setAttribute("username", username);
             session.setAttribute("password", password1);
             response.sendRedirect("/school/success.jsp");
        }else{
            response.sendRedirect("/school/loginyanzheng2.jsp");
        }
    
    
     
    %>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Insert title here</title>
    </head>
    <body>
    
    </body>
    </html>
    复制代码
    复制代码
    <%@ page language="java" contentType="text/html; charset=utf-8"
        pageEncoding="utf-8"
        import=" javax.servlet.http.HttpSession"
        %>
    <!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>
    <%
    HttpSession s = request.getSession();
    String username = s.getAttribute("username").toString();
    String password = s.getAttribute("password").toString();
    
    %>
        用户名 : <%=username %><br/>
        密码  : <%=password %>
    </body>
    </html>
  • 相关阅读:
    Redis持久化
    Redis进阶——事务、TTL、排序、消息通知、管道
    行为设计模式
    Redis数据类型
    ASP.NET并发处理
    c# 泛型有什么作用?
    IBatisNet 升级到 .Net Framework 4.0 时发现 IBatisNet 一小BUG
    【Python3】用for循环和while循环分别打印出如下格式“九九乘法表”
    Visual Studio 2010 SP1 WPF程序属性重命名BUG,小心!
    为什么用SOA架构?
  • 原文地址:https://www.cnblogs.com/WB9588/p/14641202.html
Copyright © 2011-2022 走看看