课程管理系统


javaweb 课程管理系统代码分析

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html>
 4 <html>
 5 <head>
 6 <meta charset="UTF-8">
 7 <title>首页</title>
 8 <style>
 9     .a{
10         font-size: 26px;
11         margin-top: 40px;
12     }
13 </style>
14 </head>
15 <body>
16     <div align="center">
17         <h1>课程基本信息管理系统</h1>        <!-- 系统主页 -->
18         <hr align="center" width="50%" />
19         <div class="a">
20             <a href="add.jsp">课程信息录入</a>         <!-- 页面跳转 -->
21         </div>
22         <div class="a">
23             <a href="CourseServlet?method=list">课程信息修改</a>  <!-- 页面跳转 -->
24         </div>
25         <div class="a">
26             <a href="del.jsp">课程信息删除</a>  <!-- 页面跳转 -->
27         </div>
28         <div class="a">
29             <a href="search.jsp">课程信息查询</a>  <!-- 页面跳转 -->
30         </div>
31     </div>
32 </body>
33 </html>
主页面代码

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html>
 4 <html>
 5 <head>
 6 <meta charset="UTF-8">
 7 <title>课程信息录入</title>
 8 <style>
 9     .a{
10         margin-top: 20px;
11     }
12     .b{
13         font-size: 20px;
14         width: 160px;
15         color: white;
16         background-color: greenyellow;
17     }
18 </style>
19 </head>
20 
21 <body>
22     <%
23          Object message = request.getAttribute("message");
24          if(message!=null && !"".equals(message)){
25      
26     %>
27          <script type="text/javascript">
28               alert("<%=request.getAttribute("message")%>");
29          </script>
30     <%} %>
31     <div align="center">
32         <h1 style="color: red;">课程信息录入</h1>
33         <a href="index.jsp">返回主页</a>
34         <form action="CourseServlet?method=add" method="post" onsubmit="return check()">
35             <div class="a">
36                 课程名称<input type="text" id="name" name="name"/>
37             </div>
38             <div class="a">
39                 任课教师<input type="text" id="teacher" name="teacher" />
40             </div>
41             <div class="a">
42                 上课地点<input type="text" id="classroom" name="classroom" />
43             </div>
44             <div class="a">
45                 <button type="submit" class="b">保&nbsp;&nbsp;&nbsp;存</button>
46             </div>
47         </form>
48     </div>
49     <script type="text/javascript">
50         function check() {
51             var name = document.getElementById("name");;
52             var teacher = document.getElementById("teacher");
53             var classroom = document.getElementById("classroom");
54             
55             //非空
56             if(name.value == '') {
57                 alert('课程名称为空');
58                 name.focus();
59                 return false;
60             }
61             if(teacher.value == '') {
62                 alert('教师为空');
63                 teacher.focus();
64                 return false;
65             }
66             if(classroom.value == '') {
67                 alert('上课地点为空');
68                 classroom.focus();
69                 return false;
70             }
71             
72             //教师
73             if(teacher.value != '王建民' && teacher.value != '王辉' && teacher.value != '刘丹' && teacher.value != '刘立嘉' && teacher.value != '杨子光'){
74                 alert('教师名称错误');
75                 return false;
76             }
77             
78             //教室
79             if(!/^基教/.test(classroom.value) && !/^一教/.test(classroom.value) && !/^二教/.test(classroom.value) && !/^三教/.test(classroom.value)) {
80                 alert('上课地点错误');
81                 return false;
82             }
83         }
84     </script>
85 </body>
86 </html>
录入界面

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
    .a{
        margin-top: 20px;
    }
    .b{
        font-size: 20px;
        width: 160px;
        color: white;
        background-color: greenyellow;
    }
</style>
</head>
<body>
    <%
         Object message = request.getAttribute("message");
         if(message!=null && !"".equals(message)){
     
    %>
         <script type="text/javascript">
              alert("<%=request.getAttribute("message")%>");
         </script>
    <%} %>
    <div align="center">
        <h1 style="color: red;">课程信息删除</h1>
        <a href="index.jsp">返回主页</a>
        <form action="CourseServlet?method=getcoursebyname" method="post" onsubmit="return check()">
            <div class="a">
                课程名称<input type="text" id="name" name="name"/>
            </div>
            <div class="a">
                <button type="submit" class="b">查&nbsp;&nbsp;&nbsp;找</button>
            </div>
        </form>
    </div>
    <script type="text/javascript">
        function check() {
            var name = document.getElementById("name");;
            
            //非空
            if(name.value == '') {
                alert('课程名称为空');
                name.focus();
                return false;
            }
        }
    </script>
</body>
</html>
删除界面

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
    .a{
        margin-top: 20px;
    }
    .b{
        font-size: 20px;
        width: 160px;
        color: white;
        background-color: greenyellow;
    }
</style>
</head>
<body>
    <div align="center">
        <h1 style="color: red;">课程信息查询</h1>
        <a href="index.jsp">返回主页</a>
        <form action="CourseServlet?method=search" method="post" onsubmit="return check()">
            <div class="a">
                课程名称<input type="text" id="name" name="name"/>
            </div>
            <div class="a">
                任课教师<input type="text" id="teacher" name="teacher" />
            </div>
            <div class="a">
                上课地点<input type="text" id="classroom" name="classroom" />
            </div>
            <div class="a">
                <button type="submit" class="b">查&nbsp;&nbsp;&nbsp;询</button>
            </div>
        </form>
    </div>
    <script type="text/javascript">
        function check() {
            var name = document.getElementById("name");;
            var teacher = document.getElementById("teacher");
            var classroom = document.getElementById("classroom");
            
            //非空
            if(name.value == '' && teacher.value == '' && classroom.value == '') {
                alert('请填写一个条件');
                return false;
            }
        }
    </script>
</body>
</html>
查询界面

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
    .a{
        margin-top: 20px;
    }
    .b{
        font-size: 20px;
        width: 160px;
        color: white;
        background-color: greenyellow;
    }
</style>
</head>
<body>
    <%
         Object message = request.getAttribute("message");
         if(message!=null && !"".equals(message)){
     
    %>
         <script type="text/javascript">
              alert("<%=request.getAttribute("message")%>");
         </script>
    <%} %>
    <div align="center">
        <h1 style="color: red;">课程信息修改</h1>
        <a href="index.jsp">返回主页</a>
        <form action="CourseServlet?method=update" method="post" onsubmit="return check()">
            <div class="a">
                课程名称<input type="text" id="name" name="name" value="${course.name}"/>
            </div>
            <div class="a">
                任课教师<input type="text" id="teacher" name="teacher" value="${course.teacher}"/>
            </div>
            <div class="a">
                上课地点<input type="text" id="classroom" name="classroom" value="${course.classroom}"/>
            </div>
            <input type="hidden" id="id" name="id" value="${course.id}"/>
            <div class="a">
                <button type="submit" class="b">修&nbsp;&nbsp;&nbsp;改</button>
            </div>
        </form>
    </div>
    <script type="text/javascript">
        function check() {
            var name = document.getElementById("name");;
            var teacher = document.getElementById("teacher");
            var classroom = document.getElementById("classroom");
            
            //非空
            if(name.value == '') {
                alert('课程名称为空');
                name.focus();
                return false;
            }
            if(teacher.value == '') {
                alert('教师为空');
                teacher.focus();
                return false;
            }
            if(classroom.value == '') {
                alert('上课地点为空');
                classroom.focus();
                return false;
            }
            
            //教师
            if(teacher.value != '王建民' && teacher.value != '王辉' && teacher.value != '刘丹' && teacher.value != '刘立嘉' && teacher.value != '杨子光'){
                alert('教师名称错误');
                return false;
            }
            
            //教室
            if(!/^基教/.test(classroom.value) && !/^一教/.test(classroom.value) && !/^二教/.test(classroom.value) && !/^三教/.test(classroom.value)) {
                alert('上课地点错误');
                return false;
            }
        }
    </script>
</body>
</html>
修改界面

eclipse连接数据库代码

package com;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBUtil {
    
    public static String db_url = "jdbc:mysql://localhost:3306/course?useSSL=false";
    public static String db_user = "root";
    public static String db_pass = "123456";
    
    public static Connection getConn () {
        Connection conn = null;
        
        try {
            Class.forName("com.mysql.jdbc.Driver");//加载驱动
            conn = DriverManager.getConnection(db_url, db_user, db_pass);
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        return conn;
    }
    
    /**
     * 关闭连接
     * @param state
     * @param conn
     */
    public static void close (Statement state, Connection conn) {
        if (state != null) {
            try {
                state.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    
    public static void close (ResultSet rs, Statement state, Connection conn) {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        
        if (state != null) {
            try {
                state.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

}

优质内容筛选与推荐>>
1、python 基础之第五天
2、线性icon的制作
3、C#入门笔记3 表达式及运算符
4、常见的shell命令总结
5、HDU6447(离散化扫描线+树状数组)


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号





    联系我们

    欢迎来到TinyMind。

    关于TinyMind的内容或商务合作、网站建议,举报不良信息等均可联系我们。

    TinyMind客服邮箱:support@tinymind.net.cn