javabean+jsp+servlet+jdbc从软件安装到开发实例

javabean\jsp\servlet\jdbc的作用:

JavaBean:用于传递数据,拥有与数据相关的逻辑处理。JSP:从Model接收数据并生成HTML。Servlet:接收HTTP请求并控制Model和View。jdbc:用于配置环境

首先新建course的数据库:包含name,teacher,classroom,id等字段。

源代码及包的分布

package com.hjf.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.hjf.entity.Course;
import com.hjf.util.DBUtil;

/**
 * 课程Dao
 * Dao层操作数据
 * @author Hu
 *
 */
public class CourseDao {

    /**
     * 添加
     * @param course
     * @return
     */
    public boolean add(Course course) {
        String sql = "insert into course(name, teacher, classroom) values(‘" + course.getName() + "‘,‘" + course.getTeacher() + "‘,‘" + course.getClassroom() + "‘)";
        //创建数据库链接
        Connection conn = DBUtil.getConn();
        Statement state = null;
        boolean f = false;
        int a = 0;

        try {
            state = conn.createStatement();
            state.executeUpdate(sql);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            //关闭连接
            DBUtil.close(state, conn);
        }

        if (a > 0) {
            f = true;
        }
        return f;
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    public boolean delete (int id) {
        boolean f = false;
        String sql = "delete from course where id=‘" + id + "‘";

        Connection conn = DBUtil.getConn();
        Statement state = null;
        int a = 0;

        try {
            state = conn.createStatement();
            a = state.executeUpdate(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(state, conn);
        }

        if (a > 0) {
            f = true;
        }
        return f;
    }

    /**
     * 修改
     * @param name
     * @param pass
     */
    public boolean update(Course course) {
        String sql = "update course set name=‘" + course.getName() + "‘, teacher=‘" + course.getTeacher() + "‘, classroom=‘" + course.getClassroom()
            + "‘ where id=‘" + course.getId() + "‘";
        Connection conn = DBUtil.getConn();
        Statement state = null;
        boolean f = false;
        int a = 0;

        try {
            state = conn.createStatement();
            a = state.executeUpdate(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(state, conn);
        }

        if (a > 0) {
            f = true;
        }
        return f;
    }

    /**
     * 验证课程名称是否唯一
     * true --- 不唯一
     * @param name
     * @return
     */
    public boolean name(String name) {
        boolean flag = false;
        String sql = "select name from course where name = ‘" + name + "‘";
        Connection conn = DBUtil.getConn();
        Statement state = null;
        ResultSet rs = null;

        try {
            state = conn.createStatement();
            rs = state.executeQuery(sql);
            while (rs.next()) {
                flag = true;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(rs, state, conn);
        }
        return flag;
    }

    /**
     * 通过ID得到课程信息
     * @param id
     * @return
     */
    public Course getCourseById(int id) {
        String sql = "select * from course where id =‘" + id + "‘";
        Connection conn = DBUtil.getConn();
        Statement state = null;
        ResultSet rs = null;
        Course course = null;

        try {
            state = conn.createStatement();
            rs = state.executeQuery(sql);
            while (rs.next()) {
                String name = rs.getString("name");
                String teacher = rs.getString("teacher");
                String classroom = rs.getString("classroom");
                course = new Course(id, name, teacher, classroom);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(rs, state, conn);
        }

        return course;
    }

    /**
     * 通过name得到Course
     * @param name
     * @return
     */
    public Course getCourseByName(String name) {
        String sql = "select * from course where name =‘" + name + "‘";
        Connection conn = DBUtil.getConn();
        Statement state = null;
        ResultSet rs = null;
        Course course = null;

        try {
            state = conn.createStatement();
            rs = state.executeQuery(sql);
            while (rs.next()) {
                int id = rs.getInt("id");
                String teacher = rs.getString("teacher");
                String classroom = rs.getString("classroom");
                course = new Course(id, name, teacher, classroom);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(rs, state, conn);
        }

        return course;
    }

    /**
     * 查找
     * @param name
     * @param teacher
     * @param classroom
     * @return
     */
    public List<Course> search(String name, String teacher, String classroom) {
        String sql = "select * from course where ";
        if (name != "") {
            sql += "name like ‘%" + name + "%‘";
        }
        if (teacher != "") {
            sql += "teacher like ‘%" + teacher + "%‘";
        }
        if (classroom != "") {
            sql += "classroom like ‘%" + classroom + "%‘";
        }
        List<Course> list = new ArrayList<>();
        Connection conn = DBUtil.getConn();
        Statement state = null;
        ResultSet rs = null;

        try {
            state = conn.createStatement();
            rs = state.executeQuery(sql);
            Course bean = null;
            while (rs.next()) {
                int id = rs.getInt("id");
                String name2 = rs.getString("name");
                String teacher2 = rs.getString("teacher");
                String classroom2 = rs.getString("classroom");
                bean = new Course(id, name2, teacher2, classroom2);
                list.add(bean);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(rs, state, conn);
        }

        return list;
    }

    /**
     * 全部数据
     * @param name
     * @param teacher
     * @param classroom
     * @return
     */
    public List<Course> list() {
        String sql = "select * from course";
        List<Course> list = new ArrayList<>();
        Connection conn = DBUtil.getConn();
        Statement state = null;
        ResultSet rs = null;

        try {
            state = conn.createStatement();
            rs = state.executeQuery(sql);
            Course bean = null;
            while (rs.next()) {
                int id = rs.getInt("id");
                String name2 = rs.getString("name");
                String teacher2 = rs.getString("teacher");
                String classroom2 = rs.getString("classroom");
                bean = new Course(id, name2, teacher2, classroom2);
                list.add(bean);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(rs, state, conn);
        }

        return list;
    }

}
package com.hjf.entity;

public class Course {

    private int id;
    private String name;
    private String teacher;
    private String classroom;

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getTeacher() {
        return teacher;
    }
    public void setTeacher(String teacher) {
        this.teacher = teacher;
    }
    public String getClassroom() {
        return classroom;
    }
    public void setClassroom(String classroom) {
        this.classroom = classroom;
    }

    public Course() {}

    public Course(int id, String name, String teacher, String classroom) {
        this.id = id;
        this.name = name;
        this.teacher = teacher;
        this.classroom = classroom;
    }

    public Course(String name, String teacher, String classroom) {
        this.name = name;
        this.teacher = teacher;
        this.classroom = classroom;
    }
}
package com.hjf.service;

import java.util.List;

import com.hjf.dao.CourseDao;
import com.hjf.entity.Course;

/**
 * CourseService
 * 服务层
 * @author Hu
 *
 */
public class CourseService {

    CourseDao cDao = new CourseDao();

    /**
     * 添加
     * @param course
     * @return
     */
    public boolean add(Course course) {
        boolean f = false;
        if(!cDao.name(course.getName())) {
            cDao.add(course);
            f = true;
        }
        return f;
    }

    /**
     * 删除
     */
    public void del(int id) {
        cDao.delete(id);
    }

    /**
     * 修改
     * @return
     */
    public void update(Course course) {
        cDao.update(course);
    }

    /**
     * 通过ID得到一个Course
     * @return
     */
    public Course getCourseById(int id) {
        return cDao.getCourseById(id);
    }

    /**
     * 通过Name得到一个Course
     * @return
     */
    public Course getCourseByName(String name) {
        return cDao.getCourseByName(name);
    }

    /**
     * 查找
     * @return
     */
    public List<Course> search(String name, String teacher, String classroom) {
        return cDao.search(name, teacher, classroom);
    }

    /**
     * 全部数据
     * @return
     */
    public List<Course> list() {
        return cDao.list();
    }
}
package com.hjf.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hjf.entity.Course;
import com.hjf.service.CourseService;

@WebServlet("/CourseServlet")
public class CourseServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;

    CourseService service = new CourseService();

    /**
     * 方法选择
     */
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String method = req.getParameter("method");

        if ("add".equals(method)) {
            add(req, resp);
        } else if ("del".equals(method)) {
            del(req, resp);
        } else if ("update".equals(method)) {
            update(req, resp);
        } else if ("search".equals(method)) {
            search(req, resp);
        } else if ("getcoursebyid".equals(method)) {
            getCourseById(req, resp);
        } else if ("getcoursebyname".equals(method)) {
            getCourseByName(req, resp);
        } else if ("list".equals(method)) {
            list(req, resp);
        }
    }

    /**
     * 添加
     * @param req
     * @param resp
     * @throws IOException
     * @throws ServletException
     */
    private void add(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
        req.setCharacterEncoding("utf-8");
        //获取数据
        String name = req.getParameter("name");
        String teacher = req.getParameter("teacher");
        String classroom = req.getParameter("classroom");
        Course course = new Course(name, teacher, classroom);

        //添加后消息显示
        if(service.add(course)) {
            req.setAttribute("message", "添加成功");
            req.getRequestDispatcher("add.jsp").forward(req,resp);
        } else {
            req.setAttribute("message", "课程名称重复,请重新录入");
            req.getRequestDispatcher("add.jsp").forward(req,resp);
        }
    }

    /**
     * 全部
     * @param req
     * @param resp
     * @throws ServletException
     */
    private void list(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
        req.setCharacterEncoding("utf-8");

        List<Course> courses = service.list();
        req.setAttribute("courses", courses);
        req.getRequestDispatcher("list.jsp").forward(req,resp);
    }

    /**
     * 通过ID得到Course
     * @param req
     * @param resp
     * @throws ServletException
     */
    private void getCourseById(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
        req.setCharacterEncoding("utf-8");
        int id = Integer.parseInt(req.getParameter("id"));
        Course course = service.getCourseById(id);
        req.setAttribute("course", course);
        req.getRequestDispatcher("detail2.jsp").forward(req,resp);
    }

    /**
     * 通过名字查找
     * 跳转至删除
     * @param req
     * @param resp
     * @throws IOException
     * @throws ServletException
     */
    private void getCourseByName(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
        req.setCharacterEncoding("utf-8");
        String name = req.getParameter("name");
        Course course = service.getCourseByName(name);
        if(course == null) {
            req.setAttribute("message", "查无此课程!");
            req.getRequestDispatcher("del.jsp").forward(req,resp);
        } else {
            req.setAttribute("course", course);
            req.getRequestDispatcher("detail.jsp").forward(req,resp);
        }
    }

    /**
     * 删除
     * @param req
     * @param resp
     * @throws IOException
     * @throws ServletException
     */
    private void del(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
        req.setCharacterEncoding("utf-8");
        int id = Integer.parseInt(req.getParameter("id"));
        service.del(id);
        req.setAttribute("message", "删除成功!");
        req.getRequestDispatcher("del.jsp").forward(req,resp);
    }

    /**
     * 修改
     * @param req
     * @param resp
     * @throws IOException
     * @throws ServletException
     */
    private void update(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
        req.setCharacterEncoding("utf-8");
        int id = Integer.parseInt(req.getParameter("id"));
        String name = req.getParameter("name");
        String teacher = req.getParameter("teacher");
        String classroom = req.getParameter("classroom");
        Course course = new Course(id, name, teacher, classroom);

        service.update(course);
        req.setAttribute("message", "修改成功");
        req.getRequestDispatcher("CourseServlet?method=list").forward(req,resp);
    }

    /**
     * 查找
     * @param req
     * @param resp
     * @throws ServletException
     */
    private void search(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
        req.setCharacterEncoding("utf-8");
        String name = req.getParameter("name");
        String teacher = req.getParameter("teacher");
        String classroom = req.getParameter("classroom");
        List<Course> courses = service.search(name, teacher, classroom);
        req.setAttribute("courses", courses);
        req.getRequestDispatcher("searchlist.jsp").forward(req,resp);
    }
}
package com.hjf.util;

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

/**
 * 数据库连接工具
 * @author Hu
 *
 */
public class DBUtil {

    public static String db_url = "jdbc:mysql://localhost:3306/course?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&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.cj.jdbc.Driver");//加载驱动
            conn = DriverManager.getConnection(db_url, db_user, db_pass);
            System.out.println("数据库链接正常");
        } 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();
            }
        }
    }

    public static void main(String[] args) throws SQLException {
        Connection conn = getConn();
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        String sql ="select * from course";
        pstmt = conn.prepareStatement(sql);
        rs = pstmt.executeQuery();
        if(rs.next()){
            System.out.println("空");
        }else{
            System.out.println("不空");
        }
    }
}
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%--设置页面的脚本支持语言为java—导入util包中的类—申明编码方式为UTF-8--%>
<%
request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8
response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8
%>
<%
String path = request.getContextPath(); //相对Path设置
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; //相对Path设置
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <%--文档声明--%>
<html>
  <head>
    <title>课程信息录入 </title> <%--页面标题--%>
    <body>
    <div id="Layer1" style="position:absolute; width:100%; height:100%; z-index:-1">
    <img src="C:\Users\FuHeishi826\Desktop\课程实验\Extreme\background.jpg" height="100%" width="100%"/>
    </div>
    <script type="text/javascript" language="JavaScript"> //JS
    function validate()
    {
    var name = document.forms[0].name.value; //创建变量name
    var teacher = document.forms[0].teacher.value; //创建变量teacher
    var local = document.forms[0].local.value; //创建变量address
    if(name.length <= 0){ //判断姓名位数,必填
        alert("课程名称不能为空,请输入课程名称!");
        return false;
    }
    if(teacher.value != ‘王建民‘ && teacher.value != ‘王辉‘ && teacher.value != ‘刘丹‘ && teacher.value != ‘刘立嘉‘ && teacher.value != ‘杨子光‘){
        alert(‘教师名称错误‘);
        return false;
    }

    if(!/^基教/.test(local.value) && !/^一教/.test(local.value) && !/^二教/.test(local.value) && !/^三教/.test(local.value)) {
        alert(‘上课地点错误‘);
        return false;
    }
        //document.getElementById("form").submit();
    }
    </script>
  </head>
  <body>
  <div id="Layer1" style="position:absolute; width:100%; height:100%; z-index:-1">
  <img src="C:\Users\FuHeishi826\Desktop\课程实验\Extreme\background.jpg" height="100%" width="100%"/>
  </div>
  <br><%--换行--%>
  <center>
  <h2>课程信息录入</h2><hr size="1" noshade color="#000000"><%--横线--%>
 <form action="insert.jsp" method="post" id="form" onSubmit="return validate()" ><%--跳转到insert.jsp文件,方法为post--%>
    <table width="800" border="0" align="center"> <%--表格的宽为800,居中对齐--%>
      <tr>
        <td>课程名称:
          <input type="text" name="name"></td>
      </tr>
      <tr>
        <td>授课教师:
          <input type="text" name="teacher"></td>
      </tr>
      <tr>
        <td>教学地点: <input type="text" name="local"> </td>
      </tr>
      <tr>
        <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="submit" type="submit" value="保存"/></td>
      </tr>
    </table>
    <p>&nbsp;</p>
  </form>
  <a href="showInfo.jsp">查询所有课程信息</a> <%--链接到学生信息查询页面--%>
  </center>
  </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%--设置页面的脚本支持语言为java—导入util包中的类—申明编码方式为UTF-8--%>
<%@ page import="java.sql.*"%> <%--导入java中的sql包--%>
<%@page import="com.javao.msg.DBUtil"%>
<%
request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8
response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8
%>
<%
String path = request.getContextPath(); //相对Path设置
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; //相对Path设置
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <%--文档声明--%>
<html>
  <head>
    <base href="<%=basePath%>"> <%--设置基础路径--%>
    <title>删除页面</title> <%--页面标题--%>
  </head>
<body>
<div id="Layer1" style="position:absolute; width:100%; height:100%; z-index:-1">
<img src="C:\Users\FuHeishi826\Desktop\课程实验\Extreme\background.jpg" height="100%" width="100%"/>
</div>
    <%
    request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8
    String name = request.getParameter("name");
    Connection conn = null; //定义静态数据库连接 //定义静态数据库连接
    Statement stat = null;
    ResultSet rs = null; //将rs滞空。
    conn = DBUtil.getConnection();
    stat = conn.createStatement();
    stat.executeUpdate("delete from data where name = ‘" + name + "‘"); //删除data表中的name字段
    rs = stat.executeQuery("select * from data"); //查找data表
    if(rs.next()) //判断结果集
    {
     out.print("<center><br><br><h3>删除成功!</h3></center>");
    }
    else{
    out.print("<center><h3>删除失败!</h3></center>");
    }
    %>
    <br>
    <br>
    <center><a href=addStuInfo.jsp>返回添加信息页面</a><br/><br/><a href=showInfo.jsp>返回信息查询页面</a></center> <%--设置居中--%>
    <%
    if(rs != null)
    {
        rs.close(); //关闭结果集,但是rs还是有null值。
        rs = null; //将rs滞空。
    }
        if(stat != null)
    {
        stat.close(); //关闭stat。
        stat = null; //滞空stat。
    }
        if(conn != null)
    {
        conn.close(); //关闭数据库连接
        conn = null;
    }
    %>
  </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>Welcome!</title>
</head>
<h1>欢迎来到石家庄铁道大学课程基本信息管理系统</h1><br/><br/>
<body>
<div id="Layer1" style="position:absolute; width:100%; height:100%; z-index:-1">
<img src="C:\Users\FuHeishi826\Desktop\课程实验\Extreme\background.jpg" height="100%" width="100%"/>
</div> <br/><br/>
   <p align="center">
   <a href = "addStuInfo.jsp">课程信息录入</a><br/><br/>
   <a href = "showInfo.jsp">课程信息修改</a><br/><br/>
   <a href = "showInfo.jsp">删除课程信息</a><br/><br/>
   <a href = "showInfo.jsp">查询课程信息</a><br/><br/>
   </p>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%--设置页面的脚本支持语言为java—导入util包中的类—申明编码方式为UTF-8--%>
<%@ page import="java.sql.*"%> <%--导入java中的sql包--%>
<%@page import="com.javao.msg.DBUtil"%>
<%
request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8
response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8
%>
<%
String path = request.getContextPath(); //相对Path设置
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; //相对Path设置
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <%--文档声明--%>
<html>
  <head>
    <base href="<%=basePath%>"> <%--设置基础路径,basepath为变量--%>
    <title>添加课程信息</title> <%--页面标题--%>
  </head>
   <body>
  <div id="Layer1" style="position:absolute; width:100%; height:100%; z-index:-1">
  <img src="C:\Users\FuHeishi826\Desktop\课程实验\Extreme\background.jpg" height="100%" width="100%"/>
  </div>
    <%
    request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8
    String name1 = request.getParameter("name");
    String teacher = request.getParameter("teacher");
    String local = request.getParameter("local");
    Connection conn = null; //定义静态数据库连接
    Statement stat = null;
    ResultSet rs = null; //将rs滞空。
    conn = DBUtil.getConnection();
    stat = conn.createStatement();
    //String sql = ; //向对应的数据字段添加数据
    stat.executeUpdate("insert into data(name,teacher,local) values(‘" + name1 + "‘,‘" + teacher + "‘,‘" + local + "‘)");
    rs = stat.executeQuery("select * from data"); //查找data表
%>
   <center>
   <%
    if(rs.next())
    {
    out.print("<br><h3>课程信息添加成功!</h3>");
    }
    else{
    out.print("<br><h3>课程信息添加失败!</h3>");
    }
    %>
    <br>
    <a href=addStuInfo.jsp>返回课程信息添加页面</a><br/><br/>
    <a href=showInfo.jsp>进入课程信息查询页面</a>
    </center>
     <%
    if(rs != null)
    {
        rs.close(); //关闭结果集,但是rs还是有null值。
        rs = null; //将rs滞空。
    }
        if(stat != null)
    {
        stat.close(); //关闭stat。
        stat = null; //滞空stat。
    }
        if(conn != null)
    {
        conn.close(); //关闭数据库连接
        conn = null;
    }
    %>
    </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%--设置页面的脚本支持语言为java—导入util包中的类—申明编码方式为UTF-8--%>
<%@ page import="java.sql.*"%> <%--导入java中的sql包--%>
<%@page import="com.javao.msg.DBUtil"%>
<%
request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8
response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8
%>
<%
String path = request.getContextPath(); //相对Path设置
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; //相对Path设置
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <%--文档声明--%>
<html>
  <head>
    <base href="<%=basePath%>"> <%--设置基础路径,basepath为变量--%>
    <title>按教学地点条件查询</title> <%--页面标题--%>
  </head>
  <body>
  <div id="Layer1" style="position:absolute; width:100%; height:100%; z-index:-1">
  <img src="C:\Users\FuHeishi826\Desktop\课程实验\Extreme\background.jpg" height="100%" width="100%"/>
  </div>
    <%
    String local = request.getParameter("local");
    Connection conn = null; //定义静态数据库连接
    Statement stat = null; //滞空stat。
    ResultSet rs = null; //将rs滞空。
    conn = DBUtil.getConnection();
    stat = conn.createStatement();
    rs = stat.executeQuery("select * from data where local=‘" + local + "‘");//查找data表name字段
    %>
    <br>
    <h3>符合条件的课程信息</h3> <%--标题样式3--%>
    <hr noshade>
    <br>
     <table width="450" border="100" cellSpacing=1 style="font-size:15pt;border:dashed 1pt"> <%--表格宽度450--%>
    <tr>
    <td>课程名称</td>
    <td>授课教师</td>
    <td>教学地点</td>
    </tr>
    <%
    if(rs.next())
    {
    out.print("<tr>");
    out.print("<td>" + rs.getString("name") + "</td>"); //输出name内容
    out.print("<td>" + rs.getString("teacher") + "</td>"); //输出age内容
    out.print("<td>" + rs.getString("local") + "</td>"); //输出gender内容
        %>
    <td><a href="delete.jsp?name=<%=rs.getString("name") %>">删除</a></td>
     <td><a href="update.jsp?name=<%=rs.getString("name") %>">修改</a></td>
    <%
    out.print("</tr>");
    }
    else{
    out.print("<h4>不存在此条件的信息!</h4>");
    }

    %>
    </table>
    <br>
    <a href=showInfo.jsp>返回课程信息查询页面</a>
    <%
    if(rs != null)
    {
        rs.close(); //关闭结果集,但是rs还是有null值。
        rs = null; //将rs滞空。
    }
        if(stat != null) //判断stat是否滞空。
    {
        stat.close(); //关闭stat。
        stat = null; //滞空stat。
    }
        if(conn != null)
    {
        conn.close(); //关闭数据库连接
        conn = null;
    }
    %>
  </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%--设置页面的脚本支持语言为java—导入util包中的类—申明编码方式为UTF-8--%>
<%@ page import="java.sql.*"%> <%--导入java中的sql包--%>
<%@page import="com.javao.msg.DBUtil"%>
<%
request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8
response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8
%>
<%
String path = request.getContextPath(); //相对Path设置
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; //相对Path设置
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <%--文档声明--%>
<html>
  <head>
    <base href="<%=basePath%>"> <%--设置基础路径,basepath为变量--%>
    <title>按课程名称条件查询</title> <%--页面标题--%>
  </head>
  <body>
  <div id="Layer1" style="position:absolute; width:100%; height:100%; z-index:-1">
  <img src="C:\Users\FuHeishi826\Desktop\课程实验\Extreme\background.jpg" height="100%" width="100%"/>
  </div>
    <%
    String name = request.getParameter("name");
    Connection conn = null; //定义静态数据库连接
    Statement stat = null; //滞空stat。
    ResultSet rs = null; //将rs滞空。
    conn = DBUtil.getConnection();
    stat = conn.createStatement();
    rs = stat.executeQuery("select * from data where name=‘" + name + "‘");//查找data表name字段
    %>
    <br>
    <h3>符合条件的课程信息</h3> <%--标题样式3--%>
    <hr noshade>
    <br>
     <table width="450" border="100" cellSpacing=1 style="font-size:15pt;border:dashed 1pt"> <%--表格宽度450--%>
    <tr>
    <td>课程名称</td>
    <td>授课教师</td>
    <td>教学地点</td>
    </tr>
    <%
    if(rs.next())
    {
    out.print("<tr>");
    out.print("<td>" + rs.getString("name") + "</td>"); //输出name内容
    out.print("<td>" + rs.getString("teacher") + "</td>"); //输出age内容
    out.print("<td>" + rs.getString("local") + "</td>"); //输出gender内容
        %>
    <td><a href="delete.jsp?name=<%=rs.getString("name") %>">删除</a></td>
     <td><a href="update.jsp?name=<%=rs.getString("name") %>">修改</a></td>
    <%
    out.print("</tr>");
    }
    else{
    out.print("<h4>不存在此条件的信息!</h4>");
    }

    %>
    </table>
    <br>
    <a href=showInfo.jsp>返回课程信息查询页面</a>
    <%
    if(rs != null)
    {
        rs.close(); //关闭结果集,但是rs还是有null值。
        rs = null; //将rs滞空。
    }
        if(stat != null) //判断stat是否滞空。
    {
        stat.close(); //关闭stat。
        stat = null; //滞空stat。
    }
        if(conn != null)
    {
        conn.close(); //关闭数据库连接
        conn = null;
    }
    %>
  </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%--设置页面的脚本支持语言为java—导入util包中的类—申明编码方式为UTF-8--%>
<%@ page import="java.sql.*"%> <%--导入java中的sql包--%>
<%@page import="com.javao.msg.DBUtil"%>
<%
request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8
response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8
%>
<%
String path = request.getContextPath(); //相对Path设置
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; //相对Path设置
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <%--文档声明--%>
<html>
  <head>
    <base href="<%=basePath%>"> <%--设置基础路径,basepath为变量--%>
    <title>按授课教师条件查询</title> <%--页面标题--%>
  </head>
  <body>
  <div id="Layer1" style="position:absolute; width:100%; height:100%; z-index:-1">
  <img src="C:\Users\FuHeishi826\Desktop\课程实验\Extreme\background.jpg" height="100%" width="100%"/>
  </div>
    <%
    String teacher = request.getParameter("teacher");
    Connection conn = null; //定义静态数据库连接
    Statement stat = null; //滞空stat。
    ResultSet rs = null; //将rs滞空。
    conn = DBUtil.getConnection();
    stat = conn.createStatement();
    rs = stat.executeQuery("select * from data where teacher=‘" + teacher + "‘");//查找data表name字段
    %>
    <br>
    <h3>符合条件的课程信息</h3> <%--标题样式3--%>
    <hr noshade>
    <br>
     <table width="450" border="100" cellSpacing=1 style="font-size:15pt;border:dashed 1pt"> <%--表格宽度450--%>
    <tr>
    <td>课程名称</td>
    <td>授课教师</td>
    <td>教学地点</td>
    </tr>
    <%
    if(rs.next())
    {
    out.print("<tr>");
    out.print("<td>" + rs.getString("name") + "</td>"); //输出name内容
    out.print("<td>" + rs.getString("teacher") + "</td>"); //输出age内容
    out.print("<td>" + rs.getString("local") + "</td>"); //输出gender内容
        %>
    <td><a href="delete.jsp?name=<%=rs.getString("name") %>">删除</a></td>
     <td><a href="update.jsp?name=<%=rs.getString("name") %>">修改</a></td>
    <%
    out.print("</tr>");
    }
    else{
    out.print("<h4>不存在此条件的信息!</h4>");
    }

    %>
    </table>
    <br>
    <a href=showInfo.jsp>返回课程信息查询页面</a>
    <%
    if(rs != null)
    {
        rs.close(); //关闭结果集,但是rs还是有null值。
        rs = null; //将rs滞空。
    }
        if(stat != null) //判断stat是否滞空。
    {
        stat.close(); //关闭stat。
        stat = null; //滞空stat。
    }
        if(conn != null)
    {
        conn.close(); //关闭数据库连接
        conn = null;
    }
    %>
  </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%--设置页面的脚本支持语言为java—导入util包中的类—申明编码方式为UTF-8--%>
<%@ page import="java.sql.*"%> <%--导入java中的sql包--%>
<%@page import="com.javao.msg.DBUtil"%>
<%
request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8
response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8
%>
<%
String path = request.getContextPath(); //相对Path设置
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; //相对Path设置
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <%--文档声明--%>
<html>
  <head>
    <title>课程信息</title> <%--页面标题--%>

  </head>
  <body>
  <div id="Layer1" style="position:absolute; width:100%; height:100%; z-index:-1">
  <img src="C:\Users\FuHeishi826\Desktop\课程实验\Extreme\background.jpg" height="100%" width="100%"/>
  </div>
  <%
    response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8
    request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8
    String name = request.getParameter("name");
    String teacher = request.getParameter("teacher");
    String address = request.getParameter("local");
    Connection conn = null; //定义静态数据库连接
    Statement stat = null;
    ResultSet rs = null; //将rs滞空。
    conn = DBUtil.getConnection();
    stat = conn.createStatement();
    rs = stat.executeQuery("select * from data"); //查找data表
  %>
  <br>
  <h2>课程信息</h2> <%--标题样式2--%>
  <hr noshade>
  <br>
  <h3>全部课程信息如下</h3> <%--标题样式3--%>
   <table width="562" border="100" cellSpacing=3 style="font-size:15pt;border:dashed 1pt"> <%--表格宽度450--%>
    <tr>
    <td width="110">课程名称</td>
    <td width="110">授课教师</td>
    <td width="211">教学地点</td>
    </tr>
    <%
    while(rs.next())
    {
    out.print("<tr>");
    out.print("<td>" + rs.getString("name") + "</td>"); //输出name内容
    out.print("<td>" + rs.getString("teacher") + "</td>"); //输出gender内容
    out.print("<td>" + rs.getString("local") + "</td>"); //输出major内容
    %>
    <td><a href="delete.jsp?name=<%=rs.getString("name") %>">删除</a></td>
    <td><a href="update.jsp?name=<%=rs.getString("name") %>">修改</a></td>
    <%
    out.print("</tr>");
    }
    %>
    </table>
    <br>
       <form action="select_for_name.jsp" method="post"> <%--post方法跳转到select_for_age.jsp文件--%>
    <h3>按课程名称查询:
    <input type="text" name="name"  value="" title="课程名称不能为空" ></input>
    <input type="submit" value="查询"/>
    <br>
    </h3>
    </form>
    <form action="select_for_teacher.jsp" method="post"> <%--post方法跳转到select_for_gender.jsp文件--%>
  <h3> 按授课教师查询:
    <input type="text" name="teacher" value="" title="授课教师"></input>
    <input type="submit" value="查询"/>
    <br>
  </h3>
</form>
<form action="select_for_local.jsp" method="post"> <%--post方法跳转到select_for_major.jsp文件--%>
  <h3> 按教学地点查询:
    <input type="text" name="local" value="" title="教学地点"></input>
    <input type="submit" value="查询"/>
    <br>
  </h3>
</form>
<a href=addStuInfo.jsp>返回添加课程信息页面</a>
<%
    if(rs != null)
    {
        rs.close(); //关闭结果集,但是rs还是有null值。
        rs = null; //将rs滞空。
    }
        if(stat != null)
    {
        stat.close(); //关闭stat。
        stat = null; //滞空stat。
    }
        if(conn != null)
    {
        conn.close(); //关闭数据库连接
        conn = null;
    }
    %>
  </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%--设置页面的脚本支持语言为java—导入util包中的类—申明编码方式为UTF-8--%>
<%@ page import="java.sql.*"%> <%--导入java中的sql包--%>
<%@page import="com.javao.msg.DBUtil"%>
<%
request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8
response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8
%>
<%
String path = request.getContextPath(); //相对Path设置
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; //相对Path设置
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <%--文档声明--%>
<html>
  <head>
    <title>课程信息</title> <%--页面标题--%>
    <body>
    <div id="Layer1" style="position:absolute; width:100%; height:100%; z-index:-1">
    <img src="C:\Users\FuHeishi826\Desktop\课程实验\Extreme\background.jpg" height="100%" width="100%"/>
    </div>
    <%--JS--%>
    <script type="text/javascript"">
    function validate()
    {
    var name = document.forms[0].name.value;
    var teacher = document.forms[0].age.value;
    var local = document.forms[0].major.value;
    if(name.length <= 0){
        alert("姓名不能为空,请输入姓名!");
        return false;
    }
    else if(teacher.length <= 0){
        alert("请输入正确教师姓名!");
        return false;
    }

        else if(local.length <= 0){
        alert("教学地点不能为空,请输入正确教学地点!");
        return false;
    }

    else{
        return true;
    }
        //document.getElementById("form").submit();
    }
    </script>
  </head>
  <body background="img/background.jpg">
    <%
    response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8
    request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8
    String name = request.getParameter("name");
    String teacher = request.getParameter("teacher");
    String local = request.getParameter("local");
    Connection conn = null; //定义静态数据库连接
    Statement stat = null; //滞空stat。
    ResultSet rs = null; //将rs滞空。
    conn = DBUtil.getConnection();
    stat = conn.createStatement();
    rs = stat.executeQuery("select * from data where name=‘" + name + "‘"); //查找data表id字段
  %>
  <br>
  <h2>课程信息</h2>
  <hr noshade>
  <br>
  <h3>要修改的课程信息如下</h3>
  <table width="450" border="0" cellpadding="1" cellSpacing=1 style="font-size:15pt;border:dashed 1pt">
  <tr align="center">
    <td>课程名称</td>
    <td>授课教师</td>
    <td>教学地点</td>
    </tr>
     <%
    while(rs.next())
    {
    out.print("<tr align=‘center‘>"); //居中对齐
    out.print("<td>" + rs.getString("name") + "</td>"); //输出name内容
    out.print("<td>" + rs.getString("teacher") + "</td>"); //输出gender内容
    out.print("<td>" + rs.getString("local") + "</td>"); //输出major内容
    out.print("</tr>");
    %>
    </table>
    <br>
    <br>
    <h3>将学生信息更改为:</h3>
    <form action="updateShow.jsp" method="post" onSubmit="return validate()">
<h4>课程名称:<input type="text" name="name" value="<%=rs.getString("name") %>" title="课程名称不能改变" onClick="return checkName(name)"readonly="readonly"></input><br></h4>
<h4>授课教师:<input type="text" name="teacher" title="授课教师不能为空"></input><br></h4>
<h4>教学地点:<input type="text" name="local" title="授课教师不能为空"></input><br></h4>
 <input type="submit" value="修改"/>
  </form>
<a href=addStuInfo.jsp>返回添加信息页面</a><br/><a href=showInfo.jsp>返回信息查询页面</a>
<%
  }
 %>
      <%
    if(rs != null)
    {
        rs.close(); //关闭结果集,但是rs还是有null值。
        rs = null; //将rs滞空。
    }
        if(stat != null)
    {
        stat.close(); //关闭stat。
        stat = null; //滞空stat。
    }
        if(conn != null)
    {
        conn.close(); //关闭数据库连接
        conn = null;
    }
    %>
  </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%--设置页面的脚本支持语言为java—导入util包中的类—申明编码方式为UTF-8--%>
<%@ page import="java.sql.*"%> <%--导入java中的sql包--%>
<%@page import="com.javao.msg.DBUtil"%>
<%
request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8
response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8
%>
<%
String path = request.getContextPath(); //相对Path设置
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; //相对Path设置
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <%--文档声明--%>
<html>
  <head>
    <base href="<%=basePath%>">
    <title>修改页面</title>
  </head>
  <body>
  <div id="Layer1" style="position:absolute; width:100%; height:100%; z-index:-1">
  <img src="C:\Users\FuHeishi826\Desktop\课程实验\Extreme\background.jpg" height="100%" width="100%"/>
  </div>
    <%
    request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8
    String name1 = request.getParameter("name");
    String teacher1 = request.getParameter("teacher");
    String local1 = request.getParameter("local");
    Connection conn = null; //定义静态数据库连接
    Statement stat = null;
    conn = DBUtil.getConnection();
    stat = conn.createStatement();
    stat.execute("update data set name=‘" + name1 + "‘ ,teacher=‘" + teacher1 + "‘,local=‘" + local1+"‘ where name=‘" + name1 + "‘");
    ResultSet rs = stat.executeQuery("select * from data where name=‘" + name1 + "‘"); //查找data表id字段
    %>
   <br>
   <h3>修改成功!</h3> <%--标题样式3--%>
   <br>
   <h3>修改后的信息为:</h3> <%--标题样式3--%>
   <hr noshade>
   <br>
   <br>
   <table width="450" border="100" cellSpacing=1 style="font-size:15pt;border:dashed 1pt"> <%--表格宽度450--%>
    <tr>
    <td>课程名称</td>
    <td>授课教师</td>
    <td>教学地点</td>
    </tr>
    <%
    while(rs.next())
    {
    out.print("<tr>");
    out.print("<td>" + rs.getString("name") + "</td>"); //输出name内容
    out.print("<td>" + rs.getString("teacher") + "</td>"); //输出gender内容
    out.print("<td>" + rs.getString("local") + "</td>"); //输出major内容
    out.print("</tr>");
    }
    %>
    </table>
    <br>
    <br>
    <a href=addStuInfo.jsp>返回添加信息页面</a><br/><a href=showInfo.jsp>返回信息查询页面</a>
    <%
    if(rs != null)
    {
        rs.close(); //关闭结果集,但是rs还是有null值。
        rs = null; //将rs滞空。
    }
        if(stat != null)
    {
        stat.close(); //关闭stat。
        stat = null; //滞空stat。
    }
        if(conn != null)
    {
        conn.close(); //关闭数据库连接
        conn = null;
    }
    %>
  </body>
</html>

原文地址:https://www.cnblogs.com/fuheishi/p/10092371.html

时间: 2024-10-03 18:46:09

javabean+jsp+servlet+jdbc从软件安装到开发实例的相关文章

javabean+jsp+servlet+jdbc

环境配置: 1.eclipse安装 https://www.cnblogs.com/ForestDeer/p/6647402.html 2.tomcat安装 https://blog.csdn.net/u014543872/article/details/79568712 3.数据库安装 http://www.cnblogs.com/sshoub/p/4321640.html 4.Sqlyang破解版下载 http://www.onlinedown.net/soft/24926.htm 利用ec

JSP+Servlet+JDBC+Mysql实现的博客系统

本文存在视频版本,请知悉 项目简介 项目来源于:https://gitee.com/nanpingping/jsp-blog 这次分享个人博客系统,界面简洁大气,功能齐全,是不可多得的比较容易的系统,非常适合毕业设计或者课程设计. 本系统基于JSP+Servlet+JDBC+Mysql.涉及技术少,易于理解,适合JavaWeb初学者学习使用. 难度等级:简单 技术栈 编辑器 IntelliJ IDEA 2019.1.1 (Ultimate Edition) 前端技术 基础:html+css+Ja

使用JSP+Servlet+Jdbc+Echatrs实现对豆瓣电影Top250的展示

使用JSP+Servlet+Jdbc+Echatrs实现对豆瓣电影Top250的展示 写在前面: 有的小伙伴,会吐槽啦,你这个标题有点长的啊.哈哈 ,好像是的!不过,这个也是本次案例中使用到的关键技术.如果,你正愁不会的数据可视化,那么我接下来,我会带你一步一步的实现这个数据可视化的功能. 效果图: 开发工具:我们选择的是IDEA,你还得准备一个豆瓣top250的数据源,我这里用python爬虫抓取统计了豆瓣top250电影各个国家电影数量.如何你担心,没有数据.先不用担心,我会提供的. 小建议

HTML,CSS,JavaScript,AJAX,JSP,Servlet,JDBC,Structs,Spring,Hibernate,Xml等概念

HTML: 即Hyper Text Markup Language,超文本标记语言. CSS: 层叠样式表,网页表现与内容分离的样式设计语言,相比于传统的HTML的表现而言,CSS能够对网页中对象的布局.字体.颜色等方面进行设置,并能够进行初步的交互设计. JavaScript: 基于浏览器端运行的脚本语言,无须服务器端支持,它是一种基于事件运行的编程语言,JavaScript编写的程序既可以内嵌在HTML代码中,也可以独立地以".js"格式的文件存在.JavaScript代码可以提高

【Listener】利用监听器Listener以MVC的思想通过JSP+Servlet+JDBC完成在线用户列表的输出

Servlet,监听器Listener与<[Filter]拦截器Filter>(点击打开链接)是JSP的三大核心组件,实际上监听器Listener相当于数据库里面的触发器,一旦用户触发了某种行为,则可以通过相关的Java文件执行相应的程序.用户在浏览网页的过程中,主要有打开浏览器的动作,对应的行为是Session的创建,可是,用户关闭浏览器的动作,并不是对应Session的消失,因此对于Session的消失我们意义不大:访问任意网页的动作,对应的行为是request请求的创建,request的

jsp+servlet+jdbc实现对数据库的增删改查

一.JSP和Servlet的简单介绍 1.Servlet和JSP简介: Java开发Web应用程序时用到的技术主要有两种,即Servlet和JSP,Servlet是在服务器端执行的Java程序,一个被称为Servlet容器的程序(其实就是服务器) 负责执行Java程序,而JSP(Java Server Page)则是一个页面, 由JSP容器负责执行. 2.Servlet和JSP的区别: Servlet以Java程序为主, 输出HTML代码时需要使用out.println函数,也就是说Java中内

JSP + Servlet + JDBC + Mysql 实现增删改查 课程管理系统

1.项目目录结构 2.项目环境 Eclipse IDE  MYSQL  jdk tomcat jar包 3.数据库相关配置 先创建一个course的数据库名,然后在建立一个course的表 要注意将id字段 自动递增 4.源代码 1.Course.java package com.hjf.entity; public class Course { private int id; private String name; private String teacher; private String

java -------简单的基于jsp+servlet+jdbc登录

1 2 项目结构以及数据库表图片 3 4 5 package com.jmi.booklibmanage.service; 6 7 import java.sql.Connection; 8 import java.sql.DriverManager; 9 import java.sql.ResultSet; 10 import java.sql.SQLException; 11 import java.sql.Statement; 12 13 14 15 public class Studen

JSP+Servlet+C3P0+Mysql实现的网上蛋糕店

本文存在视频版本,请知悉 项目简介 项目来源于:https://gitee.com/PositiveMumu/CakesShop/tree/master 这次分享一个蛋糕商场系统,还是很简单的系统.界面简洁但不粗糙.. 本系统基于JSP+Servlet+C3P0+Mysql+JDBC.涉及技术少,易于理解,适合JavaWeb初学者学习使用. 难度等级:简单 技术栈 编辑器 IntelliJ IDEA 2019.1.1 (Ultimate Edition) 前端技术 基础:html+css+Jav