zoukankan      html  css  js  c++  java
  • JSP第九次作业

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'register.jsp' starting page</title>
        
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">    
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->
    
      </head>
      
      <body>
       <form action="do.jsp" method="post">
    用户名:<input type="text" name="uname"  /><Br>
    密码 :<input type="password" name="upwd" /><br>
    email:<input type="text" name="uemail" /><br>
    <input type="submit" value="确认">
    </form>
      </body>
    </html>
    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'index.jsp' starting page</title>
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">    
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->
      </head>
      <script type="text/javascript">
       function mycheck() {
     
    //判断验证码是否为空
     if (form1.validationCode.value==""){
    alert("验证码不能为空,请输入验证码!");
     form1.validationCode.focus();
     return;
     }
     //判断验证码是否正确
     if (form1.validationCode.value != form1.validationCode1.value) {
     alert("请输入正确的验证码!!");
     form1.validationCode.focus();
     return;
     }
     form1.submit1();
     }
     </script>
      <body>
       <form action="dologin.jsp" method="post">
    用户名:<input type="text" name="uname" value="kitty" /><Br>
    密码 :<input type="password" name="upwd" value="777"/><br>
     <br>
     验证码:<input type="text" name="validationCode" 
     onKeyDown="if(event.keyCode==13){form1.submit.focus();}" size="6">
     <%
     int intmethod1 = (int) ((((Math.random()) * 11)) - 1);
     int intmethod2 = (int) ((((Math.random()) * 11)) - 1);
     int intmethod3 = (int) ((((Math.random()) * 11)) - 1);
     int intmethod4 = (int) ((((Math.random()) * 11)) - 1);
     //将得到的随机数进行连接
     String intsum = intmethod1 +""+ intmethod2+intmethod3+intmethod4;
     %>
     <!-- 设置隐藏域,验证比较时使用-->
     <input type="hidden" name="validationCode1" 
    value="<%=intsum%>">
     <!-- 将图片名称与得到的随机数相同的图片显示在页面上 --> 
     <img src="images/<%=intmethod1%>.png"> 
     <img src="images/<%=intmethod2%>.png"> 
     <img src="images/<%=intmethod3%>.png">
     <img src="images/<%=intmethod4%>.png"> 
     <br>
    <input type="submit" value="登录">
    <a href="register.jsp">注册</a>
    </form>
      </body>
    </html>
    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
    <%@page import="com.gd.entity.Users"%>
    <%@page import="com.gd.entity.Msg"%>
    <%@page import="com.gd.dao.MsgDao"%>
    <%@page import="com.gd.dao.UsersDao"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'do.jsp' starting page</title>
        
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">    
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->
    
      </head>
      
      <body>
      <%
      request.setCharacterEncoding("utf-8");
    Users a=new Users();
        String uname = request.getParameter("uname");
        String upwd = request.getParameter("upwd");
        String email = request.getParameter("uemail");
    
        a.setUsername(uname);
        a.setPassword(upwd);
        a.setEmail(email);
    
        UsersDao as=new UsersDao();
        as.addUsers(a);
        request.getRequestDispatcher("index.jsp").forward(request, response);
    %>
    
      </body>
    </html>
    package com.gd.dao;
    
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    
    import com.gd.entity.Users;
    
    public class UsersDao extends BaseDao {
        // 登录功能
        public boolean login(String uname, String upwd) throws SQLException {
            // 获取连接
            Connection conn = getConnection();
            // 编写sql语句
            String sql = "select * from users where username=? and password=?";
            // 执行sql语句
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, uname);
            ps.setString(2, upwd);
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {
                closeAll(conn, ps, rs);
                return true;
            } else {
                closeAll(conn, ps, rs);
                return false;
    
            }
        }
        public void addUsers(Users users) {
            try {
                Connection con = getConnection();
                String sql = "insert into users(username,password,email) values(?,?,?);";
                PreparedStatement ps = con.prepareStatement(sql);
                ps.setString(1, users.getUsername());// 给sql语句的问号赋值
                ps.setString(2, users.getPassword());
                ps.setString(3, users.getEmail());
                ps.executeUpdate();
                closeAll(con, ps, null);
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
    
        }
    //    public static void main(String[] args) {
    //        UsersDao ud=new UsersDao();
    //        try {
    //            System.out.println(ud.login("tom", "456"));
    //        } catch (SQLException e) {
    //            // TODO Auto-generated catch block
    //            e.printStackTrace();
    //        }
    //    }
    
    }

  • 相关阅读:
    Jquery EasyUI tabs处理
    C# ToString格式控制符
    SQL删除重复数据,保留一条
    stm32f4xx 的IWDG使用的一般步骤
    stm32f4xx 的EXTI使用的一般步骤
    STM32F4xx---EXTI 外部中断
    数组和指针 到 存储类(1)
    uCosII 从 OSStart开始到思维定势··········
    《C和指针》一书介绍操作符优先级
    OSTimeTick()函数解析
  • 原文地址:https://www.cnblogs.com/wangtianpeng/p/12910920.html
Copyright © 2011-2022 走看看