• 第七周JSP


    package com.gd.bean;
     
    public class pupil {
        private int sid;
        private String uname;
        private String upwd;
        public int getSid() {
            return sid;
        }
        public void setSid(int sid) {
            this.sid = sid;
        }
        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 pupil(int sid, String uname, String upwd) {
            super();
            this.sid = sid;
            this.uname = uname;
            this.upwd = upwd;
        }
        public pupil() {
            super();
        }  
    }
    package com.gd.A;
     
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
     
    import com.gd.bean.pupil;
    import com.sun.corba.se.pept.transport.Connection;
     
    public class pupilA {
        public int addstu(pupil s){
            int i=0;
             
            try {
                Class.forName("com.mysql.jdbc.Driver");
                Connection con=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql?useUnicode=true&characterEncoding=utf8", "root", "root");           
                String sql="insert into stu values(?,?,?)";        
                PreparedStatement ps=((java.sql.Connection) 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;
        }
        public int selectUser(pupil u){
            int n=0;
            try{
                Class.forName("com.mysql.jdbc.Driver");
                Connection con=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql?useUnicode=true&characterEncoding=utf8", "root", "root");   
                String sql="select uname,upwd from stu where uname=?and upwd=?";   
                PreparedStatement ps=((java.sql.Connection) con).prepareStatement(sql);
                ps.setInt(1,u.getSid());
                ps.setString(2, u.getUname());
                ps.setString(3, u.getUpwd());
                n=ps.executeUpdate();
                 
            } catch (Exception e) {
                e.printStackTrace();
            }
            return n;
        }
    }
    <%@ 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>
      </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="登录">   <input type="submit" value="注册"></td>
                </tr>
            </table>
        </form>
      </body>
    </html>
    <%@page import="com.gd.dao.pupilA"%>
    <%@page import="com.gd.bean.pupil"%>
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
        pupil s = new pupil();
        int id = Integer.parseInt(request.getParameter("sid"));
        s.setSid(id);
        String uname = request.getParameter("uname");
        s.setUname(uname);
        String upwd = request.getParameter("upwd");
        s.setUpwd(upwd);
         
        pupilA sd=new pupilA();
        if(sd.addstu(s)>0){
        }else{
        }
    %>>
    <%   
        if(uname.equals("zs")&&upwd.equals("123")){
        request.getRequestDispatcher("success.jsp").forward(request, response);
        session.setAttribute("uname",uname);
        }
        else{
        request.getRequestDispatcher("index.jsp").forward(request, response);
        }
    %>
    <%@ page language="java" import="java.util.*" contentType="text/html;charset=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>
      </head>
      <body>
       登录成功<br>
      </body>
    </html>
  • 相关阅读:
    windows 下安装securecrt 绿色版
    对Linux命令进一步学习vim(二)
    提高php编程效率的小结
    javaScript 的小技巧
    常用 Git 命令文档和命令
    你 get 了无数技能,为什么一事无成
    Ubuntu14.4下安装FTP
    对Linux命令进一步学习
    可以输入也可以下拉选择的select
    APP接口基础学习一
  • 原文地址:https://www.cnblogs.com/baigei/p/14674135.html
Copyright © 2020-2023  润新知