eclipse和数据库实现学生成绩查询系统web界面

学生成绩查询系统(eclipse+SQLserver+tomact)

开发环境

比较懒。
如果要做这种类似的系统大概都知道这些软件吧。所以这个部分比较粗糙

系统实现

  • 数据库
    创建课程信息表、学生信息表、成绩基本信息表,其中课程信息表中的课程号是成绩信息表中课程号的外键,学生信息表中的学号是成绩信息表中学号的外键。

  • 实现功能
    登陆功能;课程信息管理;学生信息管理;查询成绩。

  • 项目结构
    在这里插入图片描述
    在这里插入图片描述

  • 部分代码

数据库连接:

package util;
import java.sql.Connection;

import java.sql.DriverManager;
import java.sql.SQLException;
public class DBUtil {
	private static final String driver = "com.mysql.jdbc.Driver";
	private static final String url = "jdbc:mysql://localhost:3306/studentmanagement?useUnicode=true&characterEncoding=UTF-8";//连接数据库
	private static final String username = "root";
	private static final String password = "123456";

	private static Connection conn;

	static {
		try {
			Class.forName(driver);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	public static Connection getConnection() throws SQLException {
		if (conn == null) {
			conn = DriverManager.getConnection(url, username, password);
			return conn;
		}
		return conn;
	}

}

登录:

public class LoginServlet extends HttpServlet{
	public LoginServlet() {
		super();
	}

	/**
		 * Destruction of the servlet. <br>
		 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		response.setContentType("text/html;charset=utf-8");
		
		HttpSession session = request.getSession();
		String path = request.getContextPath();
		String action = request.getParameter("action");

		if ("login".equals(action)) {
			String inumber = request.getParameter("inumber");
			String password = request.getParameter("password");
			String identity = request.getParameter("identity");
			String[] isUserCookies = request.getParameterValues("isUseCookie");
			
			if ("student".equals(identity)) {
				// 如果登录的是学生
				StudentDao studentDao = new StudentDao();
				Student student = new Student();
				try {
					student.setSid(Integer.parseInt(inumber));
				} catch (Exception ex) {
					response.sendRedirect(path + "/failure.jsp");
					return ;
				}
				
				student.setSpwd(password);
				if (studentDao.isValid(student)) {
					// 账号密码合法
					session.setAttribute("student", student);
					if (isUserCookies != null && isUserCookies.length > 0) {
						saveCookie(inumber, password, response);
					} else {
						notSaveCookie(inumber, password, request, response);
					}		  		
					response.sendRedirect(path + "/studentMain.jsp");
				} else {
					// 不合法
					response.sendRedirect(path + "/failure.jsp");
				}
				
			} else if ("admin".equals(identity)) {
				// 如果登录的是管理员
				if ("001".equals(inumber) && "001".equals(password)) {
					// 账号密码合法
					session.setAttribute("admin", "管理员");
		  			if (isUserCookies != null && isUserCookies.length > 0) {
						saveCookie(inumber, password, response);
					} else {
						notSaveCookie(inumber, password, request, response);
					}
		  			response.sendRedirect(path + "/adminMain.jsp");
				} else {
					// 不合法
					response.sendRedirect(path + "/failure.jsp");
				}
			} else {
				response.sendRedirect(path + "/teacherMain.jsp");
			}
		} else if ("logout".equals(action)) {
			// 退出登录
			session.invalidate();
			response.sendRedirect(path + "/index.jsp");
		}
		
	} 
	
	// 记住账号密码
	public void saveCookie(String inumber, String password, HttpServletResponse response) {
		Cookie inumberCookie = new Cookie("inumber", inumber);
		Cookie passwordCookie = new Cookie("password", password);
		// 设置Cookie存储路径  否则index中取不到……
		inumberCookie.setPath("/");
		passwordCookie.setPath("/");
		inumberCookie.setMaxAge(864000);	// 10 days
		passwordCookie.setMaxAge(864000);
		response.addCookie(inumberCookie);
		response.addCookie(passwordCookie);
	}
	
	// 不记住账号密码
	public void notSaveCookie(String inumber, String password, 
			HttpServletRequest request, HttpServletResponse response) {
		Cookie[] cookies  = request.getCookies();
		for (Cookie cookie: cookies) {
			if (cookie.getName().equals("inumber") || cookie.getName().equals("password")) {
				cookie.setMaxAge(0);
				response.addCookie(cookie);
			}
		}
	}

	public void init() throws ServletException {
		// Put your code here
	}
}

学生登录的页面:

<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%@ page import="model.Student" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>学生登录</title>

	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<style type="text/css">
		* {
/* 			border:1px solid #F00; */
		}
		body {
			background:#AAFFEE url(images/studentMain.jpg);
			text-align:center;
			
		}
		#wel {
			margin: 100px 400px 0 400px;
			border:1px solid #000;
		}
		a {
			font-size:1.5em;
			background: #BBFFEE;
		}
		a:hover {background: #00BBFF;}
	</style>

  </head>
  
  <body>
  	
  	<div id="wel">
  		<h1>欢迎登录,<%=((Student)session.getAttribute("student")).getSname()%></h1>
  		<p><a href="servlet/StudentServlet?action=lookup">选课</a></p>
  		<p><a href="studentSelected.jsp">查看已选课程</a></p>
  		<p><a href="servlet/LoginServlet?action=logout">退出登录</a></p>
  	</div>
  </body>
</html>
  • 效果
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

总结+参考

部分功能存在一些问题,但是跳转是没有问题的。是在别人的代码基础之上自己调试出来的,由于时间关系没有好好完善页面、功能等。jsp感觉和html网页差不多,只是在里面加入了Java语言,不难上手。

Jsp+serlvet+mysql实现学生成绩管理系统

  • 6
    点赞
  • 85
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值