当前位置:   article > 正文

会议室管理系统_会议室管理系统c++

会议室管理系统c++
  1. <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <title>会议室使用情况</title>
  6. <script src="js/jquery-1.12.4.js"></script>
  7. <style>
  8. div{
  9. width: 500px;
  10. margin: 0px auto;
  11. text-align: right;
  12. }
  13. table{
  14. width: 500px;
  15. text-align: center;
  16. }
  17. a{
  18. color: deepskyblue;
  19. }
  20. table,tr,th,td{
  21. border: 1px solid black;
  22. }
  23. tr:nth-of-type(1){
  24. background: darkgray;
  25. }
  26. </style>
  27. </head>
  28. <body>
  29. <div>
  30. <table>
  31. <tr>
  32. <th>预定编号</th>
  33. <th>会议室</th>
  34. <th>预定人</th>
  35. <th>日期</th></tr>
  36. </table>
  37. <a href="index1.jsp">预定会议室</a>
  38. </div>
  39. </body>
  40. <script>
  41. $(function (){
  42. $.ajax({
  43. url:"cha",
  44. type:"post",
  45. data:"",
  46. dataType:"text",
  47. success: function(result){
  48. if(result.length>0){
  49. $("table").append(result);
  50. }else{
  51. alert("显示异常");
  52. }
  53. },
  54. error: function(){
  55. alert("异步请求异常");
  56. }
  57. })
  58. })
  59. </script>
  60. </html>

第二个html页面

  1. <%--
  2. Created by IntelliJ IDEA.
  3. User: Administrator
  4. Date: 2023/7/24
  5. Time: 23:10
  6. To change this template use File | Settings | File Templates.
  7. --%>
  8. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  9. <html>
  10. <head>
  11. <title>会议室预订</title>
  12. <script src="js/jquery-1.12.4.js"></script>
  13. <style>
  14. div{
  15. width: 450px;
  16. margin: 0px auto;
  17. }
  18. table{
  19. width: 450px;
  20. }
  21. tr:nth-of-type(1){
  22. background: darkgray;
  23. }
  24. h3{
  25. text-align: center;
  26. }
  27. th{
  28. text-align: right;
  29. }
  30. td{
  31. text-align: left;
  32. }
  33. table,tr,th,td{
  34. border: 1px solid black;
  35. }
  36. #aa{
  37. text-align: center;
  38. }
  39. #bb{
  40. text-align: center;
  41. }
  42. </style>
  43. </head>
  44. <body>
  45. <div>
  46. <form action="index.jsp" method="post">
  47. <table>
  48. <tr><th colspan="2" id="bb"><span>会议室预定</span></th></tr>
  49. <tr><th>会议室:</th><td><select name="" id="hys">
  50. <option>一号会议室</option>
  51. <option>二号会议室</option>
  52. <option>三号会议室</option>
  53. </select></td></tr>
  54. <tr><th>申请人:</th><td><input type="text" name="" id="sqr"></td></tr>
  55. <tr><th>预定日期:</th><td><input type="text" name="" id="ydrq">日期格式yyyy-mm-dd</td></tr>
  56. <tr><th colspan="2" id="aa"><span><input type="submit" value="申请">&nbsp;&nbsp;<input type="reset" value="重置"></span></th></tr>
  57. </table>
  58. </form>
  59. </div>
  60. </body>
  61. <script>
  62. $(function (){
  63. $("form").submit(function (){
  64. var hys = $("#hys").val();
  65. var sqr = $("#sqr").val();
  66. var ydrq = $("#ydrq").val();
  67. var rq = /^\d{4}\-\d{1,2}\-\d{1,2}$/
  68. if(sqr==null || sqr==""||
  69. ydrq=="" || ydrq==null){
  70. alert("请填写完整信息")
  71. return false;
  72. }else{
  73. if(!rq.test(ydrq)){
  74. alert("日期格式有误")
  75. return false;
  76. }else{
  77. $.ajax({
  78. url:"add",
  79. type:"post",
  80. data:{
  81. hys : $("#hys").val(),
  82. sqr : $("#sqr").val(),
  83. ydrq : $("#ydrq").val(),
  84. },
  85. dataType:"text",
  86. })
  87. }
  88. }
  89. })
  90. })
  91. </script>
  92. </html>

Dao包

basedao.java

数据库的连接跟关闭

  1. package dao;
  2. import java.sql.*;
  3. public class BaseDao {
  4. Connection conn;
  5. PreparedStatement pstmt;
  6. ResultSet rs;
  7. static{
  8. try {
  9. Class.forName("com.mysql.jdbc.Driver");
  10. } catch (ClassNotFoundException e) {
  11. throw new RuntimeException(e);
  12. }
  13. }
  14. public Connection LianJie(){
  15. if(conn==null){
  16. try {
  17. conn= DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test","root","123");
  18. } catch (SQLException e) {
  19. throw new RuntimeException(e);
  20. }
  21. }
  22. return conn;
  23. }
  24. public void GuanBi(){
  25. try {
  26. if(rs!=null){
  27. rs.close();
  28. }
  29. if(pstmt!=null){
  30. pstmt.close();
  31. }
  32. if(conn!=null){
  33. conn.close();
  34. }
  35. } catch (SQLException e) {
  36. throw new RuntimeException(e);
  37. }
  38. }
  39. }

操作数据库的增查

  1. package dao;
  2. import entity.MeetingRoom;
  3. import java.sql.*;
  4. public class MeetingRoomDao extends BaseDao{
  5. Connection conn;
  6. PreparedStatement pstmt;
  7. ResultSet rs;
  8. public String Cha(){
  9. String sql = "select * from MEETINGROOM";
  10. StringBuilder sb = new StringBuilder();
  11. if(conn==null){
  12. conn=LianJie();
  13. }
  14. try {
  15. pstmt = conn.prepareStatement(sql);
  16. rs = pstmt.executeQuery();
  17. while(rs.next()){
  18. int id = rs.getInt("id");
  19. String meetingName = rs.getString("meeting_name");
  20. Date meetingOrder = rs.getDate("meeting_order");
  21. String advanceName = rs.getString("advance_name");
  22. sb.append("<tr>" +
  23. "<th>"+id+"</th>" +
  24. "<th>"+meetingName+"</th>" +
  25. "<th>"+meetingOrder+"</th>" +
  26. "<th>"+advanceName+"</th>" +
  27. "</tr>");
  28. }
  29. } catch (SQLException e) {
  30. throw new RuntimeException(e);
  31. }
  32. GuanBi();
  33. return sb.toString();
  34. }
  35. public int Tian(MeetingRoom m){
  36. String sql = "insert into MEETINGROOM values(default,?,?,?)";
  37. if(conn==null){
  38. conn=LianJie();
  39. }
  40. int row=0;
  41. try {
  42. pstmt = conn.prepareStatement(sql);
  43. pstmt.setString(1,m.getMeeting_name());
  44. pstmt.setString(2, m.getMeeting_order());
  45. pstmt.setString(3,m.getAdvance_name());
  46. row = pstmt.executeUpdate();
  47. } catch (SQLException e) {
  48. throw new RuntimeException(e);
  49. }
  50. return row;
  51. }
  52. }

entity包内存放实体类

  1. package entity;
  2. public class MeetingRoom {
  3. private String meeting_name;
  4. private String meeting_order;
  5. private String advance_name;
  6. public MeetingRoom() {
  7. }
  8. public MeetingRoom(String meeting_name, String meeting_order, String advance_name) {
  9. this.meeting_name = meeting_name;
  10. this.meeting_order = meeting_order;
  11. this.advance_name = advance_name;
  12. }
  13. public String getMeeting_name() {
  14. return meeting_name;
  15. }
  16. public void setMeeting_name(String meeting_name) {
  17. this.meeting_name = meeting_name;
  18. }
  19. public String getMeeting_order() {
  20. return meeting_order;
  21. }
  22. public void setMeeting_order(String meeting_order) {
  23. this.meeting_order = meeting_order;
  24. }
  25. public String getAdvance_name() {
  26. return advance_name;
  27. }
  28. public void setAdvance_name(String advance_name) {
  29. this.advance_name = advance_name;
  30. }
  31. }

servlet

  1. package servlet;
  2. import dao.MeetingRoomDao;
  3. import entity.MeetingRoom;
  4. import javax.servlet.ServletException;
  5. import javax.servlet.annotation.WebServlet;
  6. import javax.servlet.http.HttpServlet;
  7. import javax.servlet.http.HttpServletRequest;
  8. import javax.servlet.http.HttpServletResponse;
  9. import java.io.IOException;
  10. @WebServlet("/add")
  11. public class AddServlet extends HttpServlet {
  12. @Override
  13. protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  14. MeetingRoomDao mrd = new MeetingRoomDao();
  15. String hys = req.getParameter("hys");
  16. String sqr = req.getParameter("sqr");
  17. String ydrq = req.getParameter("ydrq");
  18. int row = mrd.Tian(new MeetingRoom(hys,ydrq,sqr));
  19. if(row>0){
  20. System.out.println("添加成功");
  21. }else{
  22. System.out.println("添加失败");
  23. }
  24. }
  25. @Override
  26. protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  27. req.setCharacterEncoding("utf-8");
  28. doGet(req,resp);
  29. }
  30. }
  1. package servlet;
  2. import dao.MeetingRoomDao;
  3. import javax.servlet.ServletException;
  4. import javax.servlet.annotation.WebServlet;
  5. import javax.servlet.http.HttpServlet;
  6. import javax.servlet.http.HttpServletRequest;
  7. import javax.servlet.http.HttpServletResponse;
  8. import java.io.IOException;
  9. import java.io.PrintWriter;
  10. @WebServlet("/cha")
  11. public class ChaServlet extends HttpServlet {
  12. @Override
  13. protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  14. MeetingRoomDao mrd = new MeetingRoomDao();
  15. String cha = mrd.Cha();
  16. resp.setContentType("text/html");
  17. resp.setCharacterEncoding("utf-8");
  18. PrintWriter out = resp.getWriter();
  19. out.print(cha);
  20. out.close();
  21. }
  22. @Override
  23. protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  24. req.setCharacterEncoding("utf-8");
  25. doGet(req,resp);
  26. }
  27. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/182102?site
推荐阅读
相关标签
  

闽ICP备14008679号