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 '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  style="background:url(images/2.jpg)">
      <div class="contentArea">
        <form name="form1" method="post" action="control.jsp" >
            <table>
             
                <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>

      2.数据处理control.jsp

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    <%@page import="com.gd.dao.StuDao"%>
    <%@page import="com.gd.bean.Stu"%>
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
        Stu s = new Stu();
         
        String uname = request.getParameter("uname");
        s.setUname(uname);
        String upwd = request.getParameter("upwd");
        s.setUpwd(upwd);
         
        StuDao sd=new StuDao();
        if(sd.addStu(s)>0){
            //跳转注册成功页面
            request.getRequestDispatcher("welcome.jsp").forward(request,response);
        }else{
            //错误页面
            request.getRequestDispatcher("no.jsp").forward(request,response);
        }
         
         
        

      

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    package  com.he.bean;
     
    public class Stu {
        private int uid;
        private String uname;
        private String upwd;
        //访问器
        public int getUid() {
            return uid;
        }
        public void setUid(int sid) {
            this.uid = uid;
        }
        public String getUname() {
            return uname;
        }
        public void setUname(String uname) {
            this.uname = uname;
        }
        public String getUpwd() {
            return upwd;
        }
        public void setUpwd(String upwd) {
            this.upwd = upwd;
        }
        //构造器
        public Stu(int uid, String uname, String upwd) {
            super();
            this.uid = uid;
            this.uname = uname;
            this.upwd = upwd;
        }
        public Stu() {
            super();
        }
     
    }

      

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    package  com.he.dao;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import com.he.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/zdh", "root", "root");
                // 写SQL语句
                String sql = "insert into Stu values(?,?,?)";
                // 执行
                PreparedStatement ps = con.prepareStatement(sql);
                ps.setInt(1, s.getUid());
                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;
     
        }
     
     
        // 登录
     
         
    }
  • 相关阅读:
    别以为真懂Openstack: 虚拟机创建的50个步骤和100个知识点(5)
    Docker容器(三)——容器端口映射以及访问后台运行的容器实例
    Docker容器(二)——镜像制作
    Docker容器(一)——Docker的介绍与部署
    Linux的桌面虚拟化技术KVM(五)——virsh常用命令
    Linux的桌面虚拟化技术KVM(四)——虚拟机镜像格式对比与转换
    Linux的桌面虚拟化技术KVM(三)——KVM虚拟机克隆和快照
    Linux的桌面虚拟化技术KVM(一)——新建KVM虚拟机
    Linux的桌面虚拟化技术KVM(二)——远程桌面管理
    搭建jumpserver堡垒机
  • 原文地址:https://www.cnblogs.com/wishings/p/14677751.html
Copyright © 2011-2022 走看看