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

    login.jsp
    
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>register</title>
    <style type="text/css" ></style>
    </head>
    <body>
     
    <form action="success1.jsp" method="post">
        用户名:<input type="text" name="uname"><br>
        密   码:<input type="password" name="upwd"><br>
        验证码: 
              <input type="text" name="code_text" size="3" /> 
              <img src="image/yzm.jpeg"
                id="img_src" width=80 heighe=40/> 
              <a href="image/date.jpg">换一张</a> <br>
        <input type="submit" value="提交">
    </form>
         
    </body>
    </html>
    
    success.jsp
    
    <%@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("uname");
     String password1 = request.getParameter("upwd");
         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("success1.jsp");
        }else{
            response.sendRedirect("login.jsp");
        }
    %>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Insert title here</title>
    </head>
    <body>
    
    </body>
    </html>
    
    success1.jsp
    
    <%@ page language="java" contentType="text/html; charset=utf-8"
        pageEncoding="utf-8"
        import=" javas.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("uname").toString();
    String password = s.getAttribute("upwd").toString();
    
    %>
        用户名 : <%=username %><br/>
        密码  : <%=password %>
    </body>
    </html>
    

      

  • 相关阅读:
    归并排序python实现源码
    华为手机使用应用沙盒动态修改基带参数
    三星5.0以上机器最简单激活Xposed框架的经验
    python正常时间和unix时间戳时间的相互转换源码
    三星5.0以上设备最完美激活XPOSED框架的经验
    华为6.0系统设备最完美激活Xposed框架的经验
    C语言经典算法
    水果店小程序推广步骤笔记
    三星手机使用应用沙盒一键修改路由mac数据
    python通过装饰器检查函数参数的数据类型的代码
  • 原文地址:https://www.cnblogs.com/xuwei123456/p/14642968.html
Copyright © 2011-2022 走看看