本次课堂实验是做一个课程添加系统。就是制作一个界面将课程的名称,任课教师,课程教室等信息输入到界面框中,然后存入数据库。(教师信息和教室信息有限定信息)

题目如下:按照图片要求设计添加新课程界面。(0.5分) 在后台数据库中建立相应的表结构存储课程信息。(0.5分) 实现新课程添加的功能。 要求判断任课教师为王建民、刘立嘉、刘丹、王辉、杨子光五位教师的其中一位。(0.5分) 要求上课地点开头为“一教、二教、三教、基教”中的一种。(0.5分) 实现数据存储功能。(3分)

截图如下:

(开始界面)

教师不是指定教师:

地点不是指定地点:

录入成功:

输入不存在的教师和教室信息就会跳转回该页面并提示。

代码如下:

界面代码:

<%@ 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>课堂登录界面</title>
</head>
<body>


 <%=request.getAttribute("result") %>
    <form action="login.jsp" method = "get">
        <table align = "center" border = "1" width = "500">
            <tr>
                <td>课程名称:</td>
                <td>
                    <input type = "text" name = "name"/>
                </td>
            </tr>
            <tr>
                <td>任课教师:</td>
                    <td>
                        <input type = "text" name = "teacher"/>
                    </td>
            </tr>
             <tr>
                <td>上课地点:</td>
                    <td>
                        <input type = "text" name = "place"/>
                    </td>
            </tr>
            
            <tr align = "center">
                    <td colspan = "2">
                            <input type = "submit" value = "添加"/>
                    </td>
            </tr>
        </table>
    </form>

</body>
</html>

界面的执行代码:

<%@page import = "com.test.Util.DBUtil" %>
<%@page import = "java.sql.*" %>
<%@page import = "java.sql.PreparedStatement" %>
<%@ 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>
<%
    String name = request.getParameter("name");
    String teacher = request.getParameter("teacher");
    String place = request.getParameter("place");
    if(name == null || "".equals(name.trim())){
        request.setAttribute("result", "请输入课程!");
%>
        <jsp:forward page = "showlogin.jsp"></jsp:forward>
<%
    }           
    if(teacher == null || "".equals(teacher.trim())){
        request.setAttribute("result", "请输入任课教师!");
%>
        <jsp:forward page = "showlogin.jsp"></jsp:forward>
<%
    }
      if(place == null || "".equals(place.trim())){
        request.setAttribute("result", "请输入上课地点!");
%>
        <jsp:forward page = "showlogin.jsp"></jsp:forward>
<%
    }
      if( "王建民" .equals(teacher)|| "刘立嘉".equals(teacher)||"刘丹".equals(teacher)||"王辉".equals(teacher)||"杨子光".equals(teacher))
      {
          
      } 
      else{  
          request.setAttribute("result", "任课教师不存在!");
  %>
          <jsp:forward page = "showlogin.jsp"></jsp:forward>
<%
      }
      
      if(place.startsWith("基教")||place.startsWith("一教")||place.startsWith("二教")||place.startsWith("三教"))
      {}
      else{
    
          request.setAttribute("result", "教室位置不正确!");
      
 
      %>
        <jsp:forward page = "showlogin.jsp"></jsp:forward>
<%
  
 
      }
      
      
      
      
      
      
      
      Connection connection = DBUtil.getConnection();
      PreparedStatement preparedStatement = null;
      ResultSet resultSet = null;
      
          String sql = "INSERT INTO kecheng(name,teacher,place) VALUES (?,?,?) ";
          preparedStatement = connection.prepareStatement(sql);
          preparedStatement.setString(1, name);
          preparedStatement.setString(2, teacher);
          preparedStatement.setString(3, place);
          preparedStatement.execute();
          
    request.setAttribute("result", "添加完成");
    
    %>
    <jsp:forward page = "showlogin.jsp"></jsp:forward>
    </html>

 

 

 缺陷记录日志:

时间记录日志: