• 软件工程概论


    课题:

    编写教师开设课程的网页

    代码:

    package pers.sun.DataBase;

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;


    public class Data {   
     
     public static Connection getConnection() {
      //加载驱动
      try {
       Class.forName("com.mysql.jdbc.Driver").newInstance();
      } catch (InstantiationException e) {
       e.printStackTrace();
      } catch (IllegalAccessException e) {
       e.printStackTrace();
      } catch (ClassNotFoundException e) {
       e.printStackTrace();
      }
      
      String root="root";
      String password="sunyu";
      String url="jdbc:mysql://localhost:3306/user_message";
      //链接对象
      Connection con=null;
      try {
       con=DriverManager.getConnection(url,root,password);
      } catch (SQLException e) {
       e.printStackTrace();
      }
      
      return con;
      
     }
     
     //关闭资源
     public static void close(Connection con) {
       try {
        if(con!=null)
         con.close();
       } catch (SQLException e) {
        e.printStackTrace();
       }
     }
     
     public static void close(PreparedStatement pre) {
      try {
       if(pre!=null)
        pre.close();
      } catch (SQLException e) {
       e.printStackTrace();
      }
     } 
     
     public static void close(ResultSet result) {
      try {
       if(result!=null)
        result.close();
      } catch (SQLException e) {
       e.printStackTrace();
      }
     }
    }

    package pers.sun.user;

    public class Teacher {
     private String classname;
     private String tename;
     private String teplace;
     
     public String getClassname() {
      return classname;
     }
     public void setClassname(String classname) {
      this.classname = classname;
     }
     public String getTename() {
      return tename;
     }
     public void setTename(String tename) {
      this.tename = tename;
     }
     public String getTeplace() {
      return teplace;
     }
     public void setTeplace(String teplace) {
      this.teplace = teplace;
     }
     
    }

    package pers.sun.user;

    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;

    import pers.sun.DataBase.Data;

    public class UserTool {
    //1添加用户
     public static void add(User tuser) {
      //获得链接对象
      Connection con=Data.getConnection();
      //插入
      String sql="insert into user_infor(username,password) value(?,?)";
      //语句传输对象
      PreparedStatement pre=null;
      try {
       pre=con.prepareStatement(sql);
       //写进表
       pre.setString(1, tuser.getUsername());
       pre.setString(2, tuser.getPassword());
       //????刷新???
       pre.executeUpdate();
      } catch (SQLException e) {
       e.printStackTrace();
      }finally {
       Data.close(pre);
       Data.close(con);
      }
     }
     public static void add(Teacher teacher) {
      //获得链接对象
      Connection con=Data.getConnection();
      //插入
      String sql="insert into teacher_infor(classname,teachername,teachplace) value(?,?,?)";
      //语句传输对象
      PreparedStatement pre=null;
      try {
       pre=con.prepareStatement(sql);
       //写进表
       pre.setString(1, teacher.getClassname());
       pre.setString(2, teacher.getTename());
       pre.setString(3, teacher.getTeplace());
       //????刷新???
       pre.executeUpdate();
      } catch (SQLException e) {
       e.printStackTrace();
      }finally {
       Data.close(pre);
       Data.close(con);
      }
      
     }
    }

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@ page import="pers.sun.user.*" %>
    <%@ page import="pers.sun.judge.*" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <%
     
     String classnamex=request.getParameter("classname");
     String tenamex=request.getParameter("tename");
     String placex=request.getParameter("place");
     
     boolean valuex=ValueData.valueNull(request, new String[]{"classname","tename","place"});
     if(!valuex)
     {
    %> 
     <jsp:forward page="loginshow.jsp"></jsp:forward>
    <%
     }
     Teacher tea=new Teacher();
     tea.setClassname(classnamex);
     tea.setTename(tenamex);
     tea.setTeplace(placex);
     
     UserTool.add(tea);
     
    %>
    <jsp:forward page="xinxi.jsp"></jsp:forward>
    </body>
    </html>

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@ page import="pers.sun.judge.*" %>
    <%@ page import="java.util.*" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>用户登陆</title>
    </head>
    <body>
    <form action="loginhandl.jsp" method="post">
     <table align="center" border="1" width="500">
      <tr>
       <td>课程名称</td>
       <td><input type="text" name="classname">
       <%=ValueData.showError(request,"classname") %>
       </td>
      </tr>
      <tr>
       <td>任课教师</td>
       <td><input type="text" name="tename">
       <%=ValueData.showError(request,"tename") %>
       </td>
      </tr>
      <tr>
       <td>上课地点</td>
       <td><input type="text" name="place">
       <%=ValueData.showError(request,"place") %>
       </td>
      </tr>
      <tr align="center">
       <td colspan="2">
       <input type="submit" value="保存">
       <input type="reset" value="重置">
       </td>
      </tr>
     </table>
    </form>
    </body>
    </html>

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
     <h1 align="center">添加成功!</h1>
    </body>
    </html>

    ...................................................
  • 相关阅读:
    2015/8/3 接着跌
    2015/7/31 由于昨天上升缺乏量的支持,今天横盘;在箱体下边缘稍微买了一点---错误!;复文《揭秘主力坐庄流程 内幕超乎想象》,
    打包jar类库与使用jar类库
    java eclipse 监视选择指定变量
    2015/7/29 (高开,V形反转,各种指标背离——可惜没买进,填补空缺图形的心理分析)
    XP、win7下Excel 2007多窗口打开Excel的解决方法
    2015/7/28(总结昨天抄底操作失败-割肉自保)
    六首失传股诗教你如何抄底和逃顶
    2015/7/27 (主力流出-1200亿,上周五回踩,今天到底是震荡下行,还是红魔呢?——在周五成功逃顶,结果今天回调的时候被套!——教训!)
    java中byte数组与int,long,short间的转换
  • 原文地址:https://www.cnblogs.com/floakss/p/7912599.html
Copyright © 2020-2023  润新知