javaweb课程设计 学生积分管理系统(通过eclipse实现对数据库的增删改查)

        上机考试的成果,

        考试过程惊心动魄,

        本以为胜券在握,

        没想到出了差错,

        还好最后修成正果。

呀!还压上韵了,OK,不搞笑了,谈正事......在对eclipse不熟悉、对javaweb不是很感兴趣的情况之下,不得不应对上机考试,还好最后交上了试卷,有考试时间限制,课下不想再深究,主要是不感兴趣和懒,嗯~~~所以内容不完全,请包涵。简单介绍一下内容吧,主要是通过eclipse对数据库进行操作,涉及到JDBC MySQL,连接数据库,servlet框架, jsp网页+渲染... ...

求求啦!!!关注、收藏+点赞,生活乐趣多一半!!!

文章下面有投票哦!希望大家表达一下看法,我也想从中得到一些慰藉和迷茫的指引,蟹蟹~

目录

学生积分管理

预设计功能简介:学生积分数据查询,数据删除,数据添加

数据库初始数据截图:

项目结构的软件截图:

项目结构:

实现页面及运行截图:

代码粘贴:

Index.jsp:

Insert.jsp:

List.jsp:

DButil:

Dao:

Bean:

Servelt:


学生积分管理

  1. 预设计功能简介:学生积分数据查询,数据删除,数据添加

  2. 数据库初始数据截图:

  1. 项目结构的软件截图:

  • 项目结构:

  • 实现页面及运行截图:

  1. 代码粘贴:

  • Index.jsp:
<!DOCTYPE html>  

<html lang="en">  

<head>  

    <meta charset="UTF-8">  

    <meta name="viewport" content="width=device-width, initial-scale=1.0">  

    <title>简单的增删查</title>  

    <style>  

        body {  

            font-family: Arial, sans-serif;  

            margin: 0;  

            padding: 20px;  

            background-color: #f5f5f5;  

        }  
        .center-container {  

            text-align: center;  

            margin-top: 50px;  

        }  
        h1 {  

            color: #333;  

            text-transform: uppercase;  

            margin-bottom: 30px;  

        }  
        .action-link {  

            display: inline-block;  

            margin: 0 10px;  

            padding: 10px 20px;  

            background-color: #007BFF;  

            color: #fff;  

            text-decoration: none;  

            border-radius: 5px;  

            transition: background-color 0.3s;  

        }  

        .action-link:hover {  

            background-color: #0056b3;  

        }  

  
        /*  

        .modify-link {  

            display: inline-block;  

            /* 其他样式可以与 .action-link 相同或不同 */  

        }  

        */  

    </style>  

</head>  

<body>  

    <div class="center-container">  

        <h1>学生积分的增删查</h1>  

        <a href="insert.jsp" class="action-link">添加学生积分</a>  

        <a href="servlet?method=list" class="action-link">删除学生信息</a>  

        <!--  

        <a href="servlet?method=modify" class="action-link modify-link">修改</a>  

        -->  

        <a href="servlet?method=list" class="action-link">查询学生积分</a>  

    </div>  

</body>  

</html>
  • Insert.jsp:

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>添加学生积分</title>

<style>  

    body {  

        font-family: Arial, sans-serif;  

        margin: 0;  

        padding: 20px;  

        background-color: #f5f5f5;  

    }  

  

    h1 {  

        text-align: center;  

        color: #333;  

    }  

  

    .center-container {  

        text-align: center;  

        margin-top: 20px;  

    }  

  

    form {  

        margin-top: 20px;  

    }  

  

    form div {  

        margin-bottom: 10px;  

    }  

  

    form label {  

        display: inline-block;  

        width: 80px;  

    }  

  

    input[type="text"],  

    input[type="radio"] {  

        margin-right: 10px;  

    }  

  

    button {  

        padding: 10px 20px;  

        background-color: #007BFF;  

        color: #fff;  

        border: none;  

        border-radius: 5px;  

        cursor: pointer;  

    }  

  

    button:hover {  

        background-color: #0056b3;  

    }  

  

    a {  

        text-decoration: none;  

        color: #007BFF;  

    }  

  

    a:hover {  

        color: #0056b3;  

    }  

</style>  

</head>

<body>

    <%

        Object message = request.getAttribute("message");

        if (message != null && !"".equals(message)) {

    %>

    <script type="text/javascript">

              alert("<%=request.getAttribute("message")%>"); //弹出对话框

    </script>

    <%

        }

    %>

   <div class="center-container">

    <h1>添加学生积分信息</h1>  

    <a href="index.jsp">返回主页</a>  

    <form action="servlet?method=insert" method="post">  

    <div>  

        学生ID<input type="text" id="id" name="id" />  

    </div>  

    <div>  

        学生姓名<input type="text" id="name" name="name" />  

    </div>  

    <div>  

        学生积分<input type="text" id="score" name="score" />  

    </div>  

    <div>  

       性别  

    <input type="radio" id="gender_male" name="gender" value="男" />男  

    <input type="radio" id="gender_female" name="gender" value="女" />女  

</div>

    <div>  

        <button type="submit">添   加</button>  

    </div>  

    </form>  

</div>

        </form>

    </div>

</body>

</html>

  • List.jsp:

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>添加学生积分</title>

<style>  

    body {  

        font-family: Arial, sans-serif;  

        margin: 0;  

        padding: 20px;  

        background-color: #f5f5f5;  

    }  

  

    h1 {  

        text-align: center;  

        color: #333;  

    }  

  

    .center-container {  

        text-align: center;  

        margin-top: 20px;  

    }  

  

    form {  

        margin-top: 20px;  

    }  

  

    form div {  

        margin-bottom: 10px;  

    }  

  

    form label {  

        display: inline-block;  

        width: 80px;  

    }  

  

    input[type="text"],  

    input[type="radio"] {  

        margin-right: 10px;  

    }  

  

    button {  

        padding: 10px 20px;  

        background-color: #007BFF;  

        color: #fff;  

        border: none;  

        border-radius: 5px;  

        cursor: pointer;  

    }  

  

    button:hover {  

        background-color: #0056b3;  

    }  

  

    a {  

        text-decoration: none;  

        color: #007BFF;  

    }  

  

    a:hover {  

        color: #0056b3;  

    }  

</style>  

</head>

<body>

    <%

        Object message = request.getAttribute("message");

        if (message != null && !"".equals(message)) {

    %>

    <script type="text/javascript">

              alert("<%=request.getAttribute("message")%>"); //弹出对话框

    </script>

    <%

        }

    %>

   <div class="center-container">

    <h1>添加学生积分信息</h1>  

    <a href="index.jsp">返回主页</a>  

    <form action="servlet?method=insert" method="post">  

    <div>  

        学生ID<input type="text" id="id" name="id" />  

    </div>  

    <div>  

        学生姓名<input type="text" id="name" name="name" />  

    </div>  

    <div>  

        学生积分<input type="text" id="score" name="score" />  

    </div>  

    <div>  

       性别  

    <input type="radio" id="gender_male" name="gender" value="男" />男  

    <input type="radio" id="gender_female" name="gender" value="女" />女  

</div>

    <div>  

        <button type="submit">添   加</button>  

    </div>  

    </form>  

</div>

        </form>

    </div>

</body>

</html>

  • DButil:
package util;



import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;



public class DBUtil {

    private static String url = "jdbc:mysql://localhost:3306/stu_score?useUnicode=true&characterEncoding=utf8";

    private static String user = "root";

    private static String password = "123456";

    private static String jdbcName="com.mysql.jdbc.Driver";

    private Connection con=null;

    public static  Connection getConnection() {

        Connection con=null;

        try {

            Class.forName(jdbcName);

            con=DriverManager.getConnection(url, user, password);

            System.out.println("数据库连接成功");

        } catch (Exception e) {

            // TODO Auto-generated catch block

            System.out.println("数据库连接失败");

            e.printStackTrace();

        }

        return con;

        

    }

    public static void close(Connection con) {

        if(con!=null)

            try {

                con.close();

            } catch (SQLException e) {

                // TODO Auto-generated catch block

                e.printStackTrace();

            }

        

    }

    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();

            }

        }

    }



}
  • Dao:
package Dao;



 import java.sql.Connection;

 import java.sql.PreparedStatement;

 import java.sql.ResultSet;

 import java.sql.SQLException;

 import java.sql.Statement;

 import java.util.ArrayList;

 import java.util.List;

//import org.junit.jupiter.api.Test;



import bean.Bean;

import util.DBUtil;



 public class Dao {//dao层

         private DBUtil dbutil=new DBUtil();

         



     public Dao() {

         // TODO Auto-generated constructor stub

     }

//     @Test

     public boolean insert(Bean bean) {//插入数据的方法

         boolean f=false;

         String sql="insert into info(id,name,score,sex) values('"+bean.getId()+"','"+bean.getName()+"','"+bean.getScore()+"','"+bean.getSex()+"')";

         Connection conn=DBUtil.getConnection();//数据库连接,加载驱动

         Statement state=null;

         try

         {

             state=conn.createStatement();//实例化Statement对象,方便对sql语句进行操作

             System.out.println(conn);

             state.executeUpdate(sql);

             f=true;

             //执行数据库更新操作用于执行INSERT、UPDATE或DELETE语句以及SQLDDL(数据定义语言)语句,

             //例如CREATETABLE和DROPTABLE,(创建表和删除表)

         }catch(Exception e)//当try语句中s出现异常时,会执行catch中的语句

           {

             e.printStackTrace();//捕获异常的语句

           }

          finally //finally作为异常处理的一部分,它只能用在try/catch语句中,并且附带一个语句块,表示这段语句最终一定会被执行(不管有没有抛出异常),经常被用在需要释放资源的情况下。

          {

              DBUtil.close(conn);

          }

         return f;

    }

    

     public boolean delete(int id ) {//删除方法

         String sql="delete from info where id='"+id+"'";

         boolean f=false;

         Connection conn =DBUtil.getConnection();

         Statement st=null;

         try {

             st=conn.createStatement();

             st.executeUpdate(sql);

             f=true;

         } catch (SQLException e) {

             // TODO Auto-generated catch block

             e.printStackTrace();

         }

         finally{

             DBUtil.close(st, conn);

         }

         return f;

     }

     public boolean update(Bean bean) {//更新方法

        String sql="update info set name='"+bean.getName()+"',score='"+bean.getScore()+"',sex='"+bean.getSex()+"'where id='"+bean.getId()+"'";

        Connection conn=DBUtil.getConnection();

         boolean f=false;

         Statement st=null;

         try {

             st=conn.createStatement();

            st.executeUpdate(sql);

            f=true;

        } catch (SQLException e) {

             // TODO Auto-generated catch block

            e.printStackTrace();

        }

         return f;

    }

    

     public List<Bean> list(){//查询所有方法

         String sql="select * from info order by id ASC";

         Connection conn=DBUtil.getConnection();

         Statement st=null;

         List<Bean> list=new ArrayList<>();

         ResultSet rs=null;

         Bean bean=null;

         try {

             st=conn.createStatement();

             st.executeQuery(sql);

             rs=st.executeQuery(sql);

             while(rs.next()) {

                 

                 int id=rs.getInt("id");

                 String name = rs.getString("name");

                 String score = rs.getString("score");

                 String sex = rs.getString("sex");

                 bean=new Bean(id,name,score,sex);

                 list.add(bean);

             }

         } catch (SQLException e) {

             // TODO Auto-generated catch block

             e.printStackTrace();

         }

         finally {

             DBUtil.close(rs, st, conn);

         }

         return list;

     }

     

 }
  • Bean:
package bean;



public class Bean {

    private int id;

    private String name;

    private String score;

    private String sex;

    

    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 getScore() {

        return score;

    }



    public void setScore(String score) {

        this.score = score;

    }



    public String getSex() {

        return sex;

    }



    public void setSex(String sex) {

        this.sex = sex;

    }



    @Override

    public String toString() {

        return "Bean [id=" + id + ", name=" + name + ", score=" + score + ", sex=" + sex + "]";

    }



    public Bean(int id, String name, String score, String sex) {

        super();

        this.id = id;

        this.name = name;

        this.score = score;

        this.sex = sex;

    }



    public Bean() {

        // TODO Auto-generated constructor stub

    }



}

  • Servelt:
package app;



import java.io.IOException;

import java.io.UnsupportedEncodingException;

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 Dao.Dao;

import bean.Bean;



/**

 * Servlet implementation class servlet

 */

@WebServlet("/servlet")

public class servlet extends HttpServlet {

    Dao dao=new Dao();

    private static final long serialVersionUID = 1L;

    /**

     * @see HttpServlet#HttpServlet()

     */

    public servlet() {

        super();

        // TODO Auto-generated constructor stub

    }





    private void update(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        // TODO Auto-generated method stub

        request.setCharacterEncoding("utf-8");

        int id = Integer.parseInt(request.getParameter("id"));

        String name = request.getParameter("name");

        String score = request.getParameter("score");

        String sex = request.getParameter("sex");

        Bean bean=new Bean(id,name,score,sex);

        dao.update(bean);

        request.setAttribute("message", "修改成功");

        request.getRequestDispatcher("servlet?method=list").forward(request, response);

    }



    private void list(HttpServletRequest request, HttpServletResponse response) throws Exception {

        // TODO Auto-generated method stub

        request.setCharacterEncoding("utf-8");

        List<Bean> list = dao.list();

        request.setAttribute("list", list);

        request.getRequestDispatcher("list.jsp").forward(request,response);

    }



    private void delete(HttpServletRequest request, HttpServletResponse response) throws Exception, IOException {

        // TODO Auto-generated method stub

        request.setCharacterEncoding("UTF-8");

        int id=Integer.parseInt(request.getParameter("id"));

        dao.delete(id); //进行数据库的删除操作

        request.setAttribute("message", "删除成功");

        request.getRequestDispatcher("servlet?method=list").forward(request, response);

    }



    private void insert(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

        // TODO Auto-generated method stub

        request.setCharacterEncoding("utf-8");

        int id = Integer.parseInt(request.getParameter("id"));

        String name = request.getParameter("name");

        String score = request.getParameter("score");

        String sex = request.getParameter("sex");

        Bean bean=new Bean(id,name,score,sex);

        if(dao.insert(bean)) {

            request.setAttribute("message", "添加成功");

            request.getRequestDispatcher("index.jsp").forward(request, response);

        }

    }

    

    



    /**

     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)

     */

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        // TODO Auto-generated method stub

        request.setCharacterEncoding("utf-8");

        String method=request.getParameter("method");

        if("insert".equals(method)) {

            insert(request,response);

            

        }

        else if("delete".equals(method)) {

            try {

                delete(request,response);

            } catch (Exception e) {

                // TODO Auto-generated catch block

                e.printStackTrace();

            }

            

        }

        else if("update".equals(method)) {

            update(request,response);

        }

        else if("list".equals(method)) {

            try {

                list(request,response);

            } catch (Exception e) {

                // TODO Auto-generated catch block

                e.printStackTrace();

            }

        }

        

    }



    /**

     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)

     */

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        // TODO Auto-generated method stub

        doGet(request, response);

    }



}

以上主要是完整代码,关于代码相关详细知识:如数据库连接dbutil包,servlet框架介绍、认识JavaBean(JDBC),导包,jsp文件等... ... 请见我以下文章:

JavaWeb笔记(javaweb工程的创建、运行环境与架构、Tomcat、JDBC、数据库连接)-CSDN博客

文章下面有投票哦!希望大家表达一下看法,我也想从中得到一些慰藉和迷茫的指引,蟹蟹~

  • 10
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
JavaWeb实现学生成绩管理系统可以通过以下步骤进行: 1. 设计数据库:首先,需要设计一个数据库来存储学生信息和成绩数据。可以使用MySQL或其他关系型数据库来创建表格,包括学生表和成绩表,以及它们之间的关联。 2. 创建JavaWeb项目:使用JavaWeb框架(如Spring MVC、Struts2等)创建一个新的JavaWeb项目。可以使用Eclipse、IntelliJ IDEA等集成开发环境来创建项目。 3. 设计页面:根据需求,设计学生成绩管理系统的页面。可以使用HTML、CSS和JavaScript来创建用户界面,包括学生列表、成绩录入和查询等功能。 4. 编写后端代码:使用Java编写后端代码,处理前端页面的请求和响应。可以使用ServletJSP等技术来实现后端逻辑,包括数据库增删改查操作。 5. 配置Web服务器:将项目部署到Web服务器上,如Tomcat、Jetty等。配置服务器的端口号和访问路径。 6. 测试和调试:启动Web服务器,访问系统的URL,测试系统的各项功能是否正常运行。可以使用Postman等工具模拟用户请求,检查系统的响应是否正确。 7. 部署和发布:将项目打包成WAR文件,部署到生产环境的Web服务器上。确保服务器的安全性和稳定性,以提供可靠的学生成绩管理服务。 8. 维护和优化:定期检查系统的性能和安全性,及时修复bug和漏洞。根据用户反馈和需求,进行系统的优化和升级,提供更好的用户体验。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值