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

    用户表:  uid (主键,自动增长)   uname  upwd

    使用分层实现注册。(必做)

    使用分层实现登录。(选做)

    index.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 '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>
      
      <body>
        <form name="form1" method="post" action="control.jsp" >
            <table>
            <tr>    
                <td>学号:</td>
                    <td> <input type="text" name="sid" id="userName"  ></td>
                </tr>
                <tr>    
                    <td>用户名:</td>
                    <td> <input type="text" name="uname" id="userName"  ></td>
                </tr>
                <tr>    
                     <td>密码:</td>
                    <td><input type="password" name="upwd" id="pwd"></td>
                </tr>
                
                <tr>    
                    <td colspan="2"><input type="submit" value="注册"></td>
                </tr>
            </table>
        </form>
      </body>
    </html>
    

      Student.java

    package com.liu.dao;
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    
    import com.liu.bean.Stu;
    
    public class StuDao {
        // 学生数据访问类
    
        // 添加学生
        public int addStu(Stu s) {
            int i = 0;
    
            try {
                // 加载驱动
                Class.forName("com.mysql.jdbc.Driver");
                // 建立连接
                Connection con = DriverManager.getConnection(
                        "jdbc:mysql://localhost:3306/mysql", "root", "root");
                // 写SQL语句
                String sql = "insert into stu values(?,?,?)";
                // 执行
                PreparedStatement ps = con.prepareStatement(sql);
                ps.setInt(1, s.getSid());
                ps.setString(2, s.getUname());
                ps.setString(3, s.getUpwd());
                i = ps.executeUpdate();
    
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return i;
    
        }
    
    
        // 登录
    
    
    }
    

      user.jsp

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <%@ page language="java" import="java.util.*"%>
    <%@ page import ="java.sql.*"%>
    <%@page import="com.jjy.dao.jspdataDao"%>
    <%@page import="com.jjy.bean.jspdata"%>
    <html>
    <head>
        <title>欢迎你</title>
    </head>
    <body>
    <%
        request.setCharacterEncoding("utf-8");
        jspdata u= new jspdata();
        String uname = request.getParameter("name");uname.trim();
        u.setUname(uname);
        String upwd = request.getParameter("password");upwd.trim();
        u.setUpwd(upwd);
        jspdataDao ss=new jspdataDao();
        if(ss.queryUers(u)>0){
    %><p>欢迎<%=uname%></p><%
    }else{%> <p>输入错误</p><a href="index.jsp"><button>返回</button></a>
    <%
        }
    %>
     
    </body>
    </html>
    

      

  • 相关阅读:
    返回top写法技巧
    实现页面跳转至本页面的某个地方
    电信项目总结
    Struts2 ---- result
    Oracle定时器
    Oracle序列重置
    struts2---访问WEB
    分析函数
    exists 的简单介绍
    Oracle 部门员工查询
  • 原文地址:https://www.cnblogs.com/LSiyN/p/14674399.html
Copyright © 2011-2022 走看看