eclipse和数据库实现学生成绩查询系统web界面 |
您所在的位置:网站首页 › 网上查分的软件 › eclipse和数据库实现学生成绩查询系统web界面 |
学生成绩查询系统(eclipse+SQLserver+tomact)
开发环境系统实现总结+参考
开发环境
比较懒。 如果要做这种类似的系统大概都知道这些软件吧。所以这个部分比较粗糙 Java环境 下载安装eclipse和JDK,配置相应的Java环境 安装JDK的教程 安装eclipse的教程MySQL数据库 安装MySQL,配置相应的服务 MySQL安装及图形化的教程Tomact服务器 下载Tomact的压缩包,配置环境变量 安装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. */ 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 } }学生登录的页面: 学生登录 * { /* 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;} 欢迎登录, 选课 查看已选课程 退出登录 效果![]() ![]() ![]()
部分功能存在一些问题,但是跳转是没有问题的。是在别人的代码基础之上自己调试出来的,由于时间关系没有好好完善页面、功能等。jsp感觉和html网页差不多,只是在里面加入了Java语言,不难上手。 Jsp+serlvet+mysql实现学生成绩管理系统 |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |