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

    package user;
    
    public class User {
    private int number;
    private int password;
    
    public int getNumber() {
    return number;
    }
    
    public void setNumber(int number) {
    this.number = number;
    }
    
    public int getPassword() {
    return password;
    }
    
    public void setPassword(int password) {
    this.password = password;
    }
    
    public User() {
    super();
    // TODO Auto-generated constructor stub
    }
    
    public User(int number, int password) {
    super();
    this.number = number;
    this.password = password;
    }
    
    }
    
    package user;
    
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import com.mysql.jdbc.Connection;
    import com.mysql.jdbc.PreparedStatement;
    
    public class Preson {
    public static int addstu(User s) throws ClassNotFoundException,
    SQLException {
    int i = 0;
    try {
    // 加载数据库驱动
    Class.forName("com.mysql.jdbc.Driver");
    // 获取数据库连接对象
    Connection conn = (Connection) DriverManager.getConnection(
    "jdbc:mysql:///stu", "root", "123456");
    // 获取SQL语句执行者
    PreparedStatement pstmt = (PreparedStatement) conn
    .prepareStatement("insert into number values(?,?)");
    // 执行SQL语句
    ResultSet rs = (ResultSet) pstmt.executeQuery();
    // 5.处理结果集
    pstmt.setInt(1, s.getNumber());
    pstmt.setInt(2, s.getPassword());
    i = pstmt.executeUpdate();
    conn.close();
    pstmt.close();
    rs.close();
    
    } catch (Exception e) {
    }
    return i;
    }
    }
    
    <%@ 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 action="my.jsp" method="get" name="登录">
    <h2>登录界面</h2>
    账号:<input id="uname" type="text" name="user"> </br> 密码:<input
    id="upass" type="password" name="psw"></br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input
    type="submit" value="登录">&nbsp;&nbsp; <input id="login"
    type="submit" value="注册">
    </form>
    </body>
    </html>
    
    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
    <%@ page import="user.Preson"%>
    <%@ page import="user.User"%>
    <%@ page import="java.sql.*"%>
    <%@ page import="java.lang.*" %>
    <%
    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">
    </head>
    <body>
    <%
    User s = new User();
    strig name = request.getParameter("user");
    s.setNumber(name);
    string password = request.getParameter("psw");
    s.setPassword(password);
    Preson ps = new Preson();
    if (ps.addstu(s) > 0) {
    out.print("注册成功");
    } else {
    out.println("注册失败");
    }
    %>
    </body>
    </html>
  • 相关阅读:
    运用 MyPasswordSafe 规画暗码
    用Solaris Express体验OS新功能
    Linux体系上安顿Flash Media Server
    LyX 宣布支持 CJK 的 1.5 正式版
    对Unix效能器制止机能监测(下)
    Oracle在Solaris下的机能与调整简介
    Linux据有率无望在2008年打破4%
    Fedora更符合做技术人用
    Gimmie — 一个创新的 GNOME 面板步调
    Sun推出OpenSolaris 为技术创新注入活力
  • 原文地址:https://www.cnblogs.com/wzm7282/p/14678019.html
Copyright © 2011-2022 走看看