• 课程信息管理系统


    1.   创建一个Dynamic web project取名Ke

    2在wecontent中创建以下几个jsp文件

    Zhu.jsp

    <%@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=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    
    <frameset rows="100,*">
        <frame name="top" src="Top.jsp">
        <frameset cols="120,*">
        <frame name="left" src="Choice.jsp">
        <frame name="right" src="add.jsp">
        </frameset>
    
    </html>

    add.jsp

    <%@page import="Ke.Test"%>
    <%@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>
    <script type="text/javascript"">
    
        function validate()
    
        {
    
        var Ke=document.forms[0].Ke.value;
    
        var Tea=document.forms[0].Tea.value;
    
        var Di=document.forms[0].Di.value;
    
        if(Ke.length<=0){
    
            alert("课程不能为空,请输入课程!");
    
            return false;
    
        }
    
        else if(Tea.length<=0){
    
            alert("教师不能为空,请输入教师姓名!");
    
            return false;
    
        }
    
        else if(age<=0){
    
            alert("地点不能为空,请输入地点!");
    
            return false;
    
        }
    
     
    
            else if(Di.length<=0){
    
            alert("专业不能为空,请输入所学专业!");
    
            return false;
    
        }
    
     
    
        else{
    
            return true;
    
        }
    
            //document.getElementById("form").submit();
    
        }
    
        </script>
    </head>
    <body>
     <form action="addresult.jsp" method="post" id="form" onSubmit="return validate()" >
    
     <input type="hidden" name="methodName" value="0"/>
        <table border="1">
        <caption>添加课程信息</caption>
            <tr>
            <td>课程名称:</td>
            <td><input type="text" name="Ke"title="课程不能为空"></input><br></td>
            </tr>
            <tr>
            <td>任课教师:</td>
            <td>
                <select name="Tea">
                <option>请选择</option>
                <option  value="wangjianmin">王建民</option>
                <option  value="liulijia">刘立嘉</option>
                <option  value="liudan">刘丹</option>
                <option  value="wanghui">王辉</option>
                <option  value="yangziguang">杨子光</option>
                </select>
                <!-- <input type="radio" name="Tea" value="Wangjianmin">王建民
    
                <input type="radio" name="Tea" value="liulijia">刘立嘉
                <input type="radio" name="Tea" value="liudan">刘丹
                <input type="radio" name="Tea" value="wanghui">王辉
                <input type="radio" name="Tea" value="yangziguang">杨子光 -->
                </td>
            </tr>
            <tr>
            <td>上课地点:</td>
            <!-- <td><input type="text" name="classroom"></td> -->
            <td>
            <select name="Di">
                <option>请选择</option>
                <option  value="jijiao">基教</option>
                <option  value="yijiao">一教</option>
                <option  value="erjiao">二教</option>
                <option  value="sanjiao">三教</option>
                </select>
            </td>
            </tr>
            <tr>
            <td>&nbsp;</td>
            <td><input type="submit" value="提交"/></td>
            </tr>
        </table>
    </form>
     
    </body>
    </html>

    addresult.jsp

    <%@page import="Ke.Test"%>
    <%@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>
    <%
     if(Test.add(request.getParameter("Ke"),request.getParameter("Tea"),request.getParameter("Di"))==1)
     {
         {
                out.print("<script language = 'javascript'>alert('添加成功');</script>");
                response.setHeader("refresh", "0;url=Zhu.jsp");
                }
     }
     else{
         out.print("<script language = 'javascript'>alert('添加失败');</script>");
         response.setHeader("refresh", "0;url=Zhu.jsp");
            //out.println("添加失败");
     }
     %>
    </body>
    </html>

    Choice.jsp

    <%@ 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>
    <a href="add.jsp" target="right">添加课程信息</a><br>
    <a href="delete.jsp" target="right">删除课程信息</a><br>
    <a href="update.jsp" target="right">修改课程信息</a><br>
    <a href="find.jsp" target="right">查看课程信息</a>
    
    </body>
    </html>

    delete.jsp

    <%@page import="Ke.Test"%>
    <%@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=ISO-8859-1">
    <title>删除界面</title>
    </head>
    <body>
    <form action="deleteresult.jsp" method="post" id="form" onSubmit="return validate()" >
    
     <input type="hidden" name="methodName" value="0"/>
    
    <h4>  课程:<input type="text" name="Ke"title="课程不能为空"></input><br></h4>
    
    <input type="submit" value="完成"/>
       </form>
     
    </body>
    </html>

    deleteresult.jsp

    <%@page import="Ke.Test"%>
    <%@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>
    <%
     
     if(Test.delete(request.getParameter("Ke"))==1)
     {
         {
                out.print("<script language = 'javascript'>alert('添加成功');</script>");
                response.setHeader("refresh", "0;url=Zhu.jsp");
                }
     }
     else{
         out.print("<script language = 'javascript'>alert('添加失败');</script>");
         response.setHeader("refresh", "0;url=Zhu.jsp");
            //out.println("添加失败");
     }
     %>
    </body>
    </html>

    find.jsp

    <%@page import="Ke.Test"%>
    <%@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=ISO-8859-1">
    <title>查找界面</title>
    <script type="text/javascript"">
    
        function validate()
    
        {
    
        var Ke=document.forms[0].Ke.value;
    
        var Tea=document.forms[0].Tea.value;
    
        var Di=document.forms[0].Di.value;
    
        if(Ke.length<=0){
    
            alert("课程不能为空,请输入课程!");
    
            return false;
    
        }
    
        else if(Tea.length<=0){
    
            alert("教师不能为空,请输入教师姓名!");
    
            return false;
    
        }
    
        else if(age<=0){
    
            alert("地点不能为空,请输入地点!");
    
            return false;
    
        }
    
     
    
            else if(Di.length<=0){
    
            alert("专业不能为空,请输入所学专业!");
    
            return false;
    
        }
    
     
    
        else{
    
            return true;
    
        }
    
            //document.getElementById("form").submit();
    
        }
    
        </script>
    </head>
    <body>
     <form action="findresult.jsp" method="post" id="form" onSubmit="return validate()" >
    
     <input type="hidden" name="methodName" value="0"/>
    
    <h4>  课程:<input type="text" name="Ke"title="课程不能为空"></input><br></h4>
     <input type="submit" value="完成"/>
       </form>
     
    </body>
    </html>

    findresult.jsp

    <%@page import="Ke.Test"%>
    <%@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=ISO-8859-1">
    <title>查找结果</title>
    </head>
    <body>
    <%
     
     Test.find(request.getParameter("Ke"));
    out.println(Test.a_Ke());
    out.println(Test.a_Tea());
    out.println(Test.a_Di());
            
     %>
    </body>
    </html>

    Top.jsp

    <%@ 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>课程信息管理系统</h1>
    </body>
    </html>

    update.jsp

    <%@page import="Ke.Test"%>
    <%@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=ISO-8859-1">
    <title>修改界面</title>
    <script type="text/javascript"">
    
        function validate()
    
        {
    
        var Ke=document.forms[0].Ke.value;
    
        var Tea=document.forms[0].Tea.value;
    
        var Di=document.forms[0].Di.value;
    
        if(Ke.length<=0){
    
            alert("课程不能为空,请输入课程!");
    
            return false;
    
        }
    
        else if(Tea.length<=0){
    
            alert("教师不能为空,请输入教师姓名!");
    
            return false;
    
        }
    
        else if(age<=0){
    
            alert("地点不能为空,请输入地点!");
    
            return false;
    
        }
    
     
    
            else if(Di.length<=0){
    
            alert("专业不能为空,请输入所学专业!");
    
            return false;
    
        }
    
     
    
        else{
    
            return true;
    
        }
    
            //document.getElementById("form").submit();
    
        }
    
        </script>
    </head>
    <body>
     <form action="uqdateresult.jsp" method="post" id="form" onSubmit="return validate()" >
    
     <input type="hidden" name="methodName" value="0"/>
    
    <table border="1">
        <caption>修改课程信息</caption>
            <tr>
            <td>课程名称:</td>
            <td><input type="text" name="Ke"title="课程不能为空"></input><br></td>
            </tr>
            <tr>
            <td>任课教师:</td>
            <td>
                <select name="Tea">
                <option>请选择</option>
                <option  value="wangjianmin">王建民</option>
                <option  value="liulijia">刘立嘉</option>
                <option  value="liudan">刘丹</option>
                <option  value="wanghui">王辉</option>
                <option  value="yangziguang">杨子光</option>
                </select>
                <!-- <input type="radio" name="Tea" value="Wangjianmin">王建民
    
                <input type="radio" name="Tea" value="liulijia">刘立嘉
                <input type="radio" name="Tea" value="liudan">刘丹
                <input type="radio" name="Tea" value="wanghui">王辉
                <input type="radio" name="Tea" value="yangziguang">杨子光 -->
                </td>
            </tr>
            <tr>
            <td>上课地点:</td>
            <!-- <td><input type="text" name="classroom"></td> -->
            <td>
            <select name="Di">
                <option>请选择</option>
                <option  value="jijiao">基教</option>
                <option  value="yijiao">一教</option>
                <option  value="erjiao">二教</option>
                <option  value="sanjiao">三教</option>
                </select>
            </td>
            </tr>
            <tr>
            <td>&nbsp;</td>
            <td><input type="submit" value="提交"/></td>
            </tr>
        </table>
     
       </form>
     
    </body>
    </html>

    updateresult.jsp

    <%@page import="Ke.Test"%>
    <%@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=ISO-8859-1">
    <title>修改结果</title>
    </head>
    <body>
    <%
     
     if(Test.uqdate(request.getParameter("Ke"),request.getParameter("Tea"),request.getParameter("Di"))==1)
     {
         {
                out.print("<script language = 'javascript'>alert('删除成功');</script>");
                response.setHeader("refresh", "0;url=Zhu.jsp");
                }
     }
     else{
         out.print("<script language = 'javascript'>alert('删除失败');</script>");
         response.setHeader("refresh", "0;url=Zhu.jsp");
            //out.println("添加失败");
     }
     %>
    </body>
    </html>

    3. 然后在Java Resources中创建一个Ke包

    在包里创建以下几个class文件

    util.java

    package Ke;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    
    public class util {
        String user="sa";
        String password="364624";
        String url="jdbc:sqlserver://localhost:1433;DatabaseName=XVQIU";
        public  Connection getConn(){
            Connection conn=null;
            try {
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            try {
                    conn=DriverManager.getConnection(url, user, password);
            } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
            }
            return conn;
        }
        public 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();
                }
            }
        }
    }

    Test.java

    package Ke;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    
    public class util {
        String user="sa";
        String password="364624";
        String url="jdbc:sqlserver://localhost:1433;DatabaseName=XVQIU";
        public  Connection getConn(){
            Connection conn=null;
            try {
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            try {
                    conn=DriverManager.getConnection(url, user, password);
            } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
            }
            return conn;
        }
        public 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();
                }
            }
        }
    }

    4右击build选择build path 中的configure build path 在弹出窗口右侧点击add extemal jars 导入jar包

      链接: https://pan.baidu.com/s/1x_lupkstu5-9rxyoRhNz_w 提取码: 6cse 下载地址

    5下载安装sql server 

    创建名为Ke的数据库

    并创建名为Ke_c的表

    三个名为 Ke Tea Di 的列

  • 相关阅读:
    DMALL刘江峰:生鲜市场具有巨大O2O改造空间
    互联网产品经理能力体系
    Review Board——在线代码审查工具
    Java Dns Cache Manipulator
    Keepalived 双机web服务宕机检测切换系统软件
    weblogic性能调优参考
    spring的ResultSetWrappingSqlRowSet使用rs.getTimestamp取oracle数据库时分秒问题
    oracle ORA-01747(系统保留关键字)user.table.column, table.column 或列说明无效 hibernate映射oracle保留关键字
    javascript模块化编程(AMD规范的加载器)
    oracle定时运行 存储过程
  • 原文地址:https://www.cnblogs.com/zlc364624/p/10093222.html
Copyright © 2020-2023  润新知