热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Javaweb学生信息管理系统(Mysql+JSP+MVC+CSS)

原标题:Javaweb学生信息管理系统(Mysql+JSP+MVC+CSS)项目源码及数据库:链接:https://pan.baid

原标题:Javaweb学生信息管理系统(Mysql+JSP+MVC+CSS)

项目源码及数据库:

链接:https://pan.baidu.com/s/1ktUyxbOI9lljWr-HRTRIiQ?pwd=1024
提取码:1024

目录

一.项目介绍

二.运行效果

1.登录界面

2.主界面(点击学号修改学生信息)

3.增加学生界面

​编辑

三.项目目录结构

四.代码展示

1.jsp及css代码

①登录界面代码(login.jsp)

②登录界面css(login.css)

③注册用户界面(register.jsp)

④注册用户界面css(index.css)

⑤修改密码界面(UpdateLoginID.jsp)

⑥注销用户界面(DeleteLoginID.jsp)

⑦登录成功主界面(index.jsp)

⑧登陆成功界面css(show.css)

⑨点击学号,修改学生信息界面(StudentInfo.jsp)

⑩增加学生信息(add.jsp)

⑪上传作业操作(UpAndDown.jsp)

2.三层架构

①表示层Servlet

②业务逻辑层Service

③数据访问层Dao

④通用的数据库操作(DBUtils.java)

3.JavaBean封装数据

①分页帮助类(Page.java)

②封装学生信息(Student.java)

4.项目所需jar包

五.数据库表格

①登录注册表格login

②学生信息表格student1




一.项目介绍

本系统主要实现对基于Javaweb学生信息管理系统所需的各项基本功能,能够对学生信息进行增删改查等功能,并可以实现用户注册、用户登陆等功能。

数据库:Mysql

开发工具:Eclipse

开发环境:JDK+Tomcat


二.运行效果

1.登录界面

2.主界面(点击学号修改学生信息)

3.增加学生界面



三.项目目录结构

四.代码展示

1.jsp及css代码


①登录界面代码(login.jsp)

<%@ page language="java" cOntentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>


&lwww.yii666.comt;head>














②登录界面css(login.css)

*{margin:0;padding:0;}
a{text-decoration:none;color:#666;}
a:hover{
text-decoration:underline;
color:E4393C;
}
html,body
{
font:12px/150% Arial,Verdana;
}
.wrap{
width:1000px;
margin:0 auto;
}
.left{
float:left;
}
.content{
background:url(../image/login.jpg);
background-size: cover;
width:1280px;
height:559px;
}
.login-frame{
margin:50px 5% 50px 5%;
float:right;
padding:60px;
background:white;
background-color:rgba(255,255,255,0.9);
border-radius:25px;
order-right:1px #bdbdbd solid;
width:280px;
height:230px;
}
.login-frame h2{
font-size:25px;
height:40px;
margin-buttom:25px;
}
.login-frame h2 a{
font-size:15px;
color:#59c2c5;
padding-left:20px;
background:url(../image/icon5.jpg)no-repeat;
}
.login-frame .item{
height:60px;
margin-buttom:40px;
}
.login-frame .item input{
line-height:40px;
width:260px;
border:none;
border-bottom: 1px solid #59c2c5;
}
.login-btn{
display:block;
height:50px;display:block;
height:50px;
color:#fff;
background:#59c2c5;
width:265px;
font-size:16px;
line-height:30px;
text-align:center;
border-radius:10px;
border:none;
color:#fff;
background:#59c2c5;
width:265px;
font-size:16px;
line-height:30px;
text-align:center;
border-radius:10px;
border:none;
}
.login-frame .item1{
dislpay:flex;
justify-content: space-between;
margin-top:1 rem;
}
.login-frame .item1 a{
line-height:40px;
font-size:1.1rem;
margin-top:5 rem;
padding:1rem 3rem;
}

③注册用户界面(register.jsp)

<%@ page language="java" cOntentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>















用户注册

















返回
<%
String error4 = (String) request.getAttribute("error4");
if (error4!= null) {
if (error4.equals("addError")) {
out.println("注册失败!账户名已经存在!");
}
}
%>






④注册用户界面css(index.css)

*{margin:0;padding:0;}
html,body
{
font:12px/150% Arial,Verdana;
}
.content{
background:url(../image/login.jpg);
background-size: cover;
width:1280px;
height:559px;
}
.box{
margin:60px 18% 60px 18%;
float:right;
padding:30px;
background:white;
background-color:rgba(255,255,255,0.9);
border-radius:15px;

}
.item{
height:60px;
margin-buttom:40px;
}
.item input{
line-height:40px;
width:260px;
border:none;
border-bottom: 1px solid #59c2c5;
border-radius:3px;
}
.item1{
font-size:15px;
height:40px;
}
.btn{
display:block;
height:50px;
color:#fff;
background:#59c2c5;
width:265px;
font-size:16px;
line-height:30px;
text-align:center;
border-radius:10px;
border:none;
}

⑤修改密码界面(UpdateLoginID.jsp)

<%@ page language="java" cOntentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>













修改密码




















返回
<%
String error0 = (String) request.getAttribute("error0");
if (error0!= null) {
if (error0.equals("loginError")) {
out.println("用户名或密码错误,请重新输入!");
} else if (error0.equals("nologinError")) {
response.sendRedirect("login.jsp");
}
}
%>





⑥注销用户界面(DeleteLoginID.jsp)

<%@ page language="java" cOntentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>












注销账号













返回
<%
String error2 = (String) request.getAttribute("error2");
if (error2!= null) {
if (error2.equals("loginError")) {
out.println("用户名或密码错误!注销失败!");
}
}
%>





⑦登录成功主界面(index.jsp)

点击学号进入单个学生信息展示界面,可修改学生信息

点击删除删除学生信息

<%@page import="student.entity.Page"%>
<%@page import="java.util.List"%>
<%@page import="student.entity.Student"%>
<%@ page language="java" cOntentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>






















<%
Page page1 = (Page)request.getAttribute("page1");

for(Student student:page1.getStudents()){
%>







<%
}
%>

学号

姓名

年龄

专业

操作

<%=student.getSno() %> <%=student.getName() %> <%=student.getAge() %> <%=student.getDept() %> 删除


<%
if(page1.getCurrentPage()==page1.getTotalPage()-1){
%>

<%
}
else if(page1.getCurrentPage()==0){
%>

<%
}
else{
%>

<%
}
%>


<%
String error = (String)request.getAttribute("error");
if(error!=null){
if(error.equals("addError")){
out.println("增加失败!");
}
else if(error.equals("noaddError")){
out.println("增加成功!");
}
}

String error1 = (String)request.getAttribute("error1");
if(error1!=null){
if(error1.equals("deleteError")){
out.println("删除失败!");
}
else if(error1.equals("nodeleteError")){
out.println("删除成功!");
}
}
String error2 = (String)request.getAttribute("error2");
if(error2!=null){
if(error2.equals("updateError")){
out.println("修改失败!");
}
else if(error2.equals("noupdateError")){
out.println("修改成功!");
}
}


String error3 = (String)request.getAttribute("error3");
if(error3!=null){
if(error3.equals("uploadError")){
out.println("上传失败!");
}
else if(error3.equals("nouploadError")){
out.println("上传成功!");
}
}
%>




⑧登陆成功界面css(show.css)

*{margin:0;padding:0;}
html,body
{
font:12px/150% Arial,Verdana;
}
.content{
background:url(../image/index.JPG);
background-size: cover;
width:1280px;
height:559px;
}
.box{
margin:60px 18% 60px 18%;
float:right;
padding:30px;
background:white;
background-color:rgba(255,255,255,0.9);
border-radius:15px;

}
.item{
height:40px;

border-radius:15px;
}
.item a{
background-color: lightgrey;
text-decoration: none;
font-size:15px;
color:black;
border-radius:3px;
}
.item1{
font-size:15px;
height:40px;
}
table{
width:100%;
border-collapse:collapse;
}
table body{
diaplay:block;
height:300px;
overflow-y: scroll;
}
table td{
border:1px solid #A6A6A6;
height:60px;
width:300px;
text-align: center;
font-size: 15px;
}
table th{
height:60px;
border:1px solid #A6A6A6;
}

⑨点击学号,修改学生信息界面(StudentInfo.jsp)

<%@page import="student.entity.Student"%>
<%@ page language="java" cOntentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>








<%
Student student = (Student)request.getAttribute("student");
%>




修改学生信息




学号:



姓名:



年龄:



专业:



返回





⑩增加学生信息(add.jsp)

<%@ page language="java" cOntentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
















增加学生信息










文章来源地址14696.html











返回





⑪上传作业操作(UpAndDown.jsp)

<%@ page language="java" cOntentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>












上传作业

















返回





2.三层架构


①表示层Servlet

检查登录的用户名和密码是否匹配(CheckLoginServlet.java)

package student.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import student.service.IStudentService;
import student.service.impl.StudentServiceImpl;
public class CheckLoginServlet extends HttpServlet {

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String ID = request.getParameter("UID");
String pwd = request.getParameter("upwd");
IStudentService service = new StudentServiceImpl();
boolean result = service.checkLoginID(ID,pwd);
response.setContentType("text/html;charest=UTF-8");
response.setCharacterEncoding("utf-8");
if(!result) {
request.setAttribute("error", "loginError");
}else {
request.setAttribute("error", "nologinError");
}
request.getRequestDispatcher("login.jsp").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}

注册账户表示层(AddLoginIDServlet.java)

package student.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import student.service.IStudentService;
import student.service.impl.StudentServiceImpl;
/**
* Servlet implementation class AddLoginIDServlet
*/
public class AddLoginIDServlet extends HttpServlet {
private static final long serialVersiOnUID= 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String ID = request.getParameter("UID");
String pwd = request.getParameter("upwd");
IStudentService studentService = new StudentServiceImpl();
boolean result = studentService.addLoginID(ID,pwd);

response.setContentType("text/html;charest=UTF-8");
response.setCharacterEncoding("utf-8");
if(!result) {
request.setAttribute("error4", "addError");
request.getRequestDispatcher("register.jsp").forward(request, response);
}else {
request.setAttribute("error4", "noaddError");
request.getRequestDispatcher("login.jsp").forward(request, response);
}

}
/**
* @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);
}
}

修改密码表示层(UpdateLoginPwdServlet.java)

package student.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import student.service.IStudentService;
import student.service.impl.StudentServiceImpl;
/**
* Servlet implementation class UpdateLoginPwdServlet
*/
public class UpdateLoginPwdServlet extends HttpServlet {
private static final long serialVersiOnUID= 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String ID = request.getParameter("UID");
String pwd = request.getParameter("upwd");
String pwd1 = request.getParameter("upwd1");
IStudentService service = new StudentServiceImpl();
boolean result = service.checkLoginID(ID,pwd);
response.setContentType("text/html;charest=UTF-8");
response.setCharacterEncoding("utf-8");
if(!result) {
request.setAttribute("error0", "loginError");
request.getRequestDispatcher("UpdateLoginPwd.jsp").forward(request, response);
}else {
request.setAttribute("error0", "nologinError");
boolean result1 = service.updateLoginPwd(ID,pwd1);
if(!result1) {
request.getRequestDispatcher("UpdateLoginPwd.jsp").forward(request, response);
}else {
request.setAttribute("error1", "noupdateError");
request.getRequestDispatcher("login.jsp").forward(request, response);
}
}
}
/**
* @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);
}
}

注销用户表示层(DeleteLoginIDServlet.java)

package student.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import student.service.IStudentService;
import student.service.impl.StudentServiceImpl;
/**
* Servlet implementation class DeleteLoginIDServlet
*/
public class DeleteLoginIDServlet extends HttpServlet {
private static final long serialVersiOnUID= 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String ID = request.getParameter("UID");
String pwd = request.getParameter("upwd");
IStudentService service = new StudentServiceImpl();
boolean result = service.checkLoginID(ID,pwd);
boolean result1 = service.deleteLoginID(ID);
response.setContentType("text/html;charest=UTF-8");
response.setCharacterEncoding("utf-8");
if(!result) {
request.setAttribute("error2", "loginError");
request.getRequestDispatcher("DeleteLoginID.jsp").forward(request, response);
}else {
request.setAttribute("error2", "nologinError");
if(!result1) {
request.setAttribute("error3", "deleteError");
request.getRequestDispatcher("DeleteLoginID.jsp").forward(request, response);
}else {
request.setAttribute("error3", "nodeleteError");
request.getRequestDispatcher("login.jsp").forward(request, response);
}
}
}
/**
* @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);
}
}

分页显示(QueryStudentByPageServlet.java)

package student.servlet;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import student.entity.Page;
import student.entity.Student;
import student.service.IStudentService;
import student.service.impl.StudentServiceImpl;
public class QueryStudentByPageServlet extends HttpServlet {
private static final long serialVersiOnUID= 1L;
public QueryStudentByPageServlet() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
IStudentService studentService = new StudentServiceImpl();
int count = studentService.getTotalCount();

Page page = new Page();


String cPage = request.getParameter("currentPage");

if(cPage == null) {
cPage = "0";
}
int currentPage = Integer.parseInt(cPage);
page.setCurrentPage(currentPage);
int totalCount = studentService.getTotalCount();
page.setTotalCount(totalCount);
int pageSize = 4;

page.setPageSize(pageSize);

List students = studentService.queryStudentsByPage(currentPage, pageSize);

page.setStudents(students);
request.setAttribute("page1", page);
request.getRequestDispatcher("index.jsp").forward(request, response);
}
/**
* @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);
}
}

按学号查询学生信息(QueryStudentBySnoServlet.java)

package student.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import student.entity.Student;
import student.service.IStudentService;
import student.service.impl.StudentServiceImpl;
public class QueryStudentBySnoServlet extends HttpServlet {

/**
*
*/
private static final long serialVersiOnUID= 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
int sno = Integer.parseInt(request.getParameter("sno"));
IStudentService service = new StudentServiceImpl();
Student student = service.queryStudentBySno(sno);
request.setAttribute("student", student);//将查询到的request信息放在request域中
request.getRequestDispatcher("StudentInfo.jsp").forward(request,response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}

增加学生信息(AddStudentServlet.java)

package student.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import student.entity.Student;
import student.service.IStudentService;
import student.service.impl.StudentServiceImpl;
public class AddStudentServlet extends HttpServlet {
/**
*
*/
private static final long serialVersiOnUID= 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String name = request.getParameter("name");
int sno = Integer.parseInt(request.getParameter("sno"));
int age = Integer.parseInt(request.getParameter("age"));
String dept = request.getParameter("dept");
Student student = new Student(name, sno, age, dept);

IStudentService studentService = new StudentServiceImpl();
boolean result = studentService.addStudent(student);

response.setContentType("text/html;charest=UTF-8");
response.setCharacterEncoding("utf-8");
if(!result) {
request.setAttribute("error", "addError");
}else {
request.setAttribute("error", "noaddError");
}
request.getRequestDispatcher("QueryStudentByPageServlet").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}

删除学生信息(DeleteStudentServlet.java)

package student.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import student.service.IStudentService;
import student.service.impl.StudentServiceImpl;
/**
* Servlet implementation class DeleteStudentServlet
*/
public class DeleteStudentServlet extends HttpServlet {

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
int sno = Integer.parseInt(request.getParameter("sno"));
IStudentService service = new StudentServiceImpl();
boolean result = service.deleteStudentBySno(sno);
response.setContentType("text/html;charest=UTF-8");
response.setCharacterEncoding("utf-8");
if(!result) {
request.setAttribute("error1", "deleteError");
}else {
request.setAttribute("error1", "nodeleteError");
}
request.getRequestDispatcher("QueryStudentByPageServlet").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}

修改学生信息表示层(UpdateStudentServlet.java)

package student.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import student.entity.Student;
import student.service.IStudentService;
import student.service.impl.StudentServiceImpl;
public class UpdateStudentServlet extends HttpServlet {
/**
*
*/
private static final long serialVersiOnUID= 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
String name = request.getParameter("name");
int sno = Integer.parseInt(request.getParameter("sno"));
int age = Integer.parseInt(request.getParameter("age"));
String dept = request.getParameter("dept");
Student student = new Student(name, age, dept);

System.out.println(sno);

IStudentService service = new StudentServiceImpl();
boolean result = service.updateStudentBySno(sno, student);

response.setContentType("text/html;charest=UTF-8");
response.setCharacterEncoding("utf-8");
if(!result) {
request.setAttribute("error2", "updateError");
}else {
request.setAttribute("error2", "noupdateError");
}
request.getRequestDispatcher("QueryStudentByPageServlet").forward(request, response);
}

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

上传作业(UploadServlet.java)

package student.servlet;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadBase;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import student.service.IStudentService;
import student.service.impl.StudentServiceImpl;
public class UploadServlet extends HttpServlet {
private static final long serialVersiOnUID= 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
String name = null;
int sno = -1;

boolean isMutipart = ServletFileUpload.isMultipartContent(request);
if(isMutipart) {
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
factory.setRepository(new File("D:\\uploadtemp"));
List items = null;
try {
items = upload.parseRequest(request);
} catch (FileUploadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Iterator iter = items.iterator();
while(iter.hasNext()) {
FileItem item= iter.next();
String fileName = item.getName();
String itemName = item.getFieldName();
if(item.isFormField()) {
if(itemName.equals("name")){
name = item.getString("utf-8");
}else if(itemName.equals("sno")) {
sno =Integer.parseInt(item.getString("utf-8"));
}else {

}
}else {
//定义上传路径:指定上传的位置
String path = "D:\\upload";
File file = new File(path,fileName);
try {
item.write(file);
} catch (Exception e) {
e.printStackTrace();
}
}
}
IStudentService studentService = new StudentServiceImpl();
boolean result = studentService.upLoadWork(sno,name);

System.out.println(name+sno);
System.out.println(result);
if(!result) {
request.setAttribute("error3", "uploadError");
request.getRequestDispatcher("QueryStudentByPageServlet").forward(request, response);

}else{
request.setAttribute("error3", "nouploadError");
request.getRequestDispatcher("QueryStudentByPageServlet").forward(request, response);

}
}
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}

②业务逻辑层Service

Service接口(IStudentService.java)

package student.service;
import java.util.List;
import student.entity.Student;
public interface IStudentService {
//查询全部学生信息
public List queryAllStudents();
//按照学号查询学生信息
public Student queryStudentBySno(int sno);
//删除学生信息
public boolean deleteStudentBySno(int sno) ;

//更改学生信息
public boolean updateStudentBySno(int sno, Student student) ;

//增加学生信息
public boolean addStudent(Student student) ;

//查询总数据
public int getTotalCount();
//分页
public List queryStudentsByPage(int current, int pageSize);
//检查登陆账户和密码
public boolean checkLoginID(String ID,String pwd);
//注册账户
public boolean addLoginID(String ID, String pwd);
//更改密码
public boolean updateLoginPwd(String ID,String pwd1);
//注销账号
public boolean deleteLoginID(String ID);
//判断ID是否存在
public boolean IDExist(String ID);
//判断上传作业输入的学生信息是否存在
public boolean upLoadWork(int sno, String name);
}

接口的实现类(StudentServiceImpl.java)

package student.service.impl;
import java.util.List;
import student.dao.IStudentDao;
import student.dao.impl.StudentDaoImpl;
import student.entity.Student;
import student.service.IStudentService;
import student.util.DBUtil;
//业务逻辑层:逻辑性的增删改查(增:查+增),对dao层进行的组装
public class StudentServiceImpl implements IStudentService{
IStudentDao studentDao = new StudentDaoImpl();
//查询全部学生信息
public List queryAllStudents(){
return studentDao.queryAllStudents();
}
//按照学号查询学生信息
public Student queryStudentBySno(int sno) {
return studentDao.queryStudentBySno(sno);

}
//删除学生信息
public boolean deleteStudentBySno(int sno) {
if(studentDao.isExist(sno)) {
return studentDao.deleteStudentBySno(sno);
}
return false;
}


//更改学生信息
public boolean updateStudentBySno(int sno, Student student) {
return studentDao.updateStudentBySno(sno, student);
}


//增加学生信息
public boolean addStudent(Student student) {
if(!studentDao.isExist(student.getSno())) {
studentDao.addStudent(student);
return true;
}else {
System.out.println("学号重复!");
return false;
}
}

//查询总条数
@Override
public int getTotalCount() {
return studentDao.getTotalCount();
}
//查询当前页的数据集合
@Override
public List queryStudentsByPage(int current, int pageSize) {
return studentDao.queryStudentByPage(current, pageSize);
}


@Override
public boolean checkLoginID(String ID, String pwd) {
return studentDao.checkLoginID(ID, pwd);
}
@Override
public boolean addLoginID(String ID, String pwd) {
return studentDao.addLoginID(ID,pwd);

}
@Override
public boolean updateLoginPwd(String ID, String pwd1) {
return studentDao.updateLoginPwd(ID,pwd1);
}
@Override
public boolean deleteLoginID(String ID) {
return studentDao.deleteLoginID(ID);
}
@Override
public boolean IDExist(String ID) {
return studentDao.IDExist(ID);
}
@Override
public boolean upLoadWork(int sno, String name) {
return studentDao.upLoadWork(sno,name);
}


}

③数据访问层Dao

接口(IStudentDao.java)

package student.dao;
import java.util.List;
import student.entity.Student;
public interface IStudentDao {
public boolean updateLoginPwd(String ID,String pwd1);
//查询全部学生信息
public List queryAllStudents();


//判断此人是否存在
public boolean isExist(int sno) ;

//增加学生信息
public boolean addStudent(Student student);
//删除学生信息
public boolean deleteStudentBySno(int sno);

//根据sno找到要修改的学生,然后再进行修改
public boolean updateStudentBySno(int sno,Student student);
//根据学号查询学生信息
public Student queryStudentBySno(int sno);

//查询总数据数
public int getTotalCount();
//currentPage:当前页(页码)pageSize:页面大小(每页显示的数据条数)
public List queryStudentByPage(int currentPage,int pageSize);

public boolean checkLoginID(String ID,String pwd);
public boolean addLoginID(String ID, String pwd);
public boolean deleteLoginID(String ID);
public boolean IDExist(String ID);
public boolean upLoadWork(int sno, String name);
}

接口的实现类(StudentDaoImpl.java)

package student.dao.impl;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import student.dao.IStudentDao;
import student.entity.Student;
import student.util.DBUtil;
public class StudentDaoImpl implements IStudentDao{

private final String URL = "jdbc:mysql://localhost:3306/STUDENT?useSSL=false&serverTimezOne=UTC";
private final String UserName = "root";
private final String Pwd = "123456";
String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
//查询全部学生信息
public List queryAllStudents(){
PreparedStatement pstmt = null;
Student student = null;
List students = new ArrayList<>();
ResultSet rs = null;
try {
String sql = "select * from student1";
rs = DBUtil.executeQuery(sql, null);
while(rs.next()) {
int sno= rs.getInt("sno");
String name = rs.getString("name");
int age = rs.getInt("age");
String dept = rs.getString("dept");
student = new Student(name, sno, age, dept);
students.add(student);
}
return students;

} catch(Exception e) {
e.printStackTrace();
return null;
}
finally {
DBUtil.closeAll(rs, pstmt, DBUtil.connection);
}
}


//判断此人是否存在
public boolean isExist(int sno) {
return queryStudentBySno(sno) == null? false:true;
}

//增加学生信息
public boolean addStudent(Student student) {
String sql = "insert into student1(name,sno,age,dept) values(?,?,?,?)";
Object[] params = {student.getName(),student.getSno(),student.getAge(),student.getDept()};
return DBUtil.executeUpdate(sql, params);
}
//删除学生信息
public boolean deleteStudentBySno(int sno) {
String sql = "delete from student1 where sno =?";
Object[] params = {sno};
return DBUtil.executeUpdate(sql, params);
}

//根据sno找到要修改的学生,然后再进行修改
public boolean updateStudentBySno(int sno,Student student) {
String sql = "update student1 set name =?,age=?,dept=? where sno=?";
Object[] params = {student.getName(),student.getAge(),student.getDept(),sno};

return DBUtil.executeUpdate(sql, params);

}
//根据学号查询学生信息
public Student queryStudentBySno(int sno){
PreparedStatement pstmt = null;
Student student = null;
Connection cOnnection= null;
ResultSet rs = null;
try {
Class.forName(JDBC_DRIVER);
cOnnection= DriverManager.getConnection(URL,UserName,Pwd);
String sql = "select * from student1 where sno = ?";
pstmt = connection.prepareStatement(sq文章来源站点https://www.yii666.com/l);
pstmt.setInt(1, sno);
rs = pstmt.executeQuery();
if(rs.next()) {
int no= rs.getInt("sno");
String name = rs.getString("name");
int age = rs.getInt("age");
String dept = rs.getString("dept");
student = new Student(name, no, age, dept);
}
return student;

} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
} catch(SQLException e) {
e.printStackTrace();
return null;
}catch(Exception e) {
e.printStackTrace();
return null;
}
finally {
DBUtil.closeAll(rs, pstmt, DBUtil.connection);
}
}
@Override
public int getTotalCount() {//查询总数据数
String sql = "select count(1) from student1";
return DBUtil.getTotalCount(sql);
}
@Override
public List queryStudentByPage(int currentPage, int pageSize) {
String sql = "select * from student1 order by sno asc limit ?,?";
Object[] params = {currentPage*pageSize,pageSize};

List students = new ArrayList<>();
ResultSet rs = DBUtil.executeQuery(sql, params);
try {
while(rs.next()) {
Student student = new Student(rs.getString("name"),rs.getInt("sno"),rs.getInt("age"),rs.getString("dept"));
students.add(student);
}
} catch (SQLException e) {
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}
return students;
}
@Override
public boolean checkLoginID(String ID, String pwd){
int count = 0;
String sql = "select * from login where ID=? and pwd=?";
Object[] params = {ID,pwd};
ResultSet rs = DBUtil.executeQuery(sql, params);
try {
while(rs.next()) {
count++;
}
if(count>0)
return true;
else
return false;
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
@Override
public boolean addLoginID(String ID, String pwd) {
// TODO Auto-generated method stub
String sql = "insert into login(ID,pwd) values(?,?)";
Object[] params = {ID,pwd};
return DBUtil.executeUpdate(sql, params);
}
@Override
public boolean updateLoginPwd(String ID, String pwd1) {
String sql = "update login set pwd =? where ID=?";
Object[] params = {pwd1,ID};
return DBUtil.executeUpdate(sql, params);
}
@Override
public boolean deleteLoginID(String ID) {
String sql = "delete from login where ID =?";
Object[] params = {ID};
return DBUtil.executeUpdate(sql, params);
}
@Override
public boolean IDExist(String ID) {
String sql = "select *from login where ID = ?";
Object[] params = {ID};
return DBUtil.executeUpdate(sql, params);
}
@Override
public boolean upLoadWork(int sno, String name) {
int count = 0;
String sql = "select *from student1 where sno = ? and name = ?";
Object[] params = {sno,name};
ResultSet rs = DBUtil.executeQuery(sql, params);
try {
while(rs.next()) {
www.yii666.com count++;
}
if(count>0)
return true;
else
return false;
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
}

④通用的数据库操作(DBUtils.java)

package student.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;
import java.util.ArrayList;
import java.util.List;
import student.entity.Student;
//通用的数据库操作方法
public class DBUtil {
private static final String URL = "jdbc:mysql://localhost:3306/STUDENT?useSSL=false&serverTimezOne=UTC";
private static final String UserName = "root";
private static final String Pwd = "123456";
private static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
public static Connection cOnnection= null;
public static PreparedStatement pstmt = null;
public static ResultSet rs = null;

//查询总数
public static int getTotalCount(String sql){
int count = -1;
try {
pstmt = createPreParedStatement(sql,null);
rs = pstmt.executeQuery();
if(rs.next()) {
count = rs.getInt(1);
}
} catch (SQLException e) {
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}finally {
closeAll(rs,pstmt,connection);
}
return count;
}

//增删改
public static boolean executeUpdate(String sql,Object[] params) {
try {
pstmt = createPreParedStatement(sql,params);
int count = pstmt.executeUpdate();

System.out.println(count);
if(count>0) {
return true;
}
else {
return false;
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
return false;
} catch(SQLException e) {
e.printStackTrace();
return false;
}catch(Exception e) {
e.printStackTrace();
return false;
}
finally {
closeAll(null,pstmt,connection);
}
}
public static void closeAll(ResultSet rs,Statement stmt,Connection connection){
try{
if(rs!=null)rs.close();
if(pstmt!=null)pstmt.close();
if(connection!=null)connection.close();

}catch(SQLException e) {
e.printStackTrace();
}
}

public static PreparedStatement createPreParedStatement(String sql,Object[] params) throws ClassNotFoundException, SQLException {
pstmt = getConnection().prepareStatement(sql);
if(params!=null) {
for(int i = 0;i pstmt.setObject(i+1, params[i]);
}
}
return pstmt;
}

public static Connection getConnection() throws ClassNotFoundException, SQLException {
Class.forName(JDBC_DRIVER);
return DriverManager.getConnection(URL,UserName,Pwd);
}
//通用的查
public static ResultSet executeQuery(String sql,Object[] params){
List students = new ArrayList<>();
Student student = null;

try {
pstmt = createPreParedStatement(sql,params);
rs = pstmt.executeQuery();

return rs;

} catch(SQLException e) {
e.printStackTrace();
return null;
}catch(Exception e) {
e.printStackTrace();
return null;
}

}
}

3.JavaBean封装数据


①分页帮助类(Page.java)

package student.entity;
import java.util.List;
//分页帮助类
public class Page {
private int currentPage;
private int pageSize;
private int totalCount;
private int totalPage;
private List students;
public Page() {

}
public Page(int currentPage, int pageSize, int totalCount, int totalPage, List students) {
this.currentPage = currentPage;
this.pageSize = pageSize;
this.totalCount = totalCount;
this.totalPage = totalPage;
this.students = students;
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getPageSize() {
return pageSize;
}

public void setPageSize(int pageSize) {
this.pageSize = pageSize;
this.totalPage = this.totalCount%this.pageSize==0?this.totalCount/this.pageSize:this.totalCount/this.pageSize+1;
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
public int getTotalPage() {
return totalPage;
}


public List getStudents() {
return students;
}
public void setStudents(List students) {
this.students = students;
}
}

②封装学生信息(Student.java)

package student.entity;
public class Student {
private String name;
private int sno;
private int age;
private String dept;

public Student(int sno) {
this.sno = sno;
}

public Student() {

}
public Student(String name, int age, String dept) {
this.name = name;
this.age = age;
this.dept = dept;
}
public Student(String name, int sno, int age, String dept) {
this.name = name;
this.sno = sno;
this.age = age;
this.dept = dept;
}

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getSno() {
return sno;
}
public void setSno(int sno) {
this.sno = sno;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getDept() {
return dept;
}
public void setDept(String dept) {
this.dept = dept;
}
public String toString() {
return this.getSno()+"-"+this.getName()+"-"+this.getAge()+"-"+this.getDept();

}
}

4.项目所需jar包


项目需要3个jar包,前两个jar包属于文件上传所需,最后一个为连接数据库的jar包

下载官网地址:https://mvnrepository.com/


五.数据库表格

本人用的是mysql数据库,直接在mysql数据库中新建表格

①登录注册表格login

②学生信息表格student1

来源于:Javaweb学生信息管理系统(Mysql+JSP+MVC+CSS)


推荐阅读
  • 本文介绍了如何利用Struts1框架构建一个简易的四则运算计算器。通过采用DispatchAction来处理不同类型的计算请求,并使用动态Form来优化开发流程,确保代码的简洁性和可维护性。同时,系统提供了用户友好的错误提示,以增强用户体验。 ... [详细]
  • 作为软件工程专业的学生,我深知课堂上教师讲解速度之快,很多时候需要课后自行消化和巩固。因此,撰写这篇Java Web开发入门教程,旨在帮助初学者更好地理解和掌握基础知识。通过详细记录学习过程,希望能为更多像我一样在基础方面还有待提升的学员提供有益的参考。 ... [详细]
  • Linux CentOS 7 安装PostgreSQL 9.5.17 (源码编译)
    近日需要将PostgreSQL数据库从Windows中迁移到Linux中,LinuxCentOS7安装PostgreSQL9.5.17安装过程特此记录。安装环境&#x ... [详细]
  • 网站访问全流程解析
    本文详细介绍了从用户在浏览器中输入一个域名(如www.yy.com)到页面完全展示的整个过程,包括DNS解析、TCP连接、请求响应等多个步骤。 ... [详细]
  • MySQL 5.7 学习指南:SQLyog 中的主键、列属性和数据类型
    本文介绍了 MySQL 5.7 中主键(Primary Key)和自增(Auto-Increment)的概念,以及如何在 SQLyog 中设置这些属性。同时,还探讨了数据类型的分类和选择,以及列属性的设置方法。 ... [详细]
  • javascript分页类支持页码格式
    前端时间因为项目需要,要对一个产品下所有的附属图片进行分页显示,没考虑ajax一张张请求,所以干脆一次性全部把图片out,然 ... [详细]
  • 原文网址:https:www.cnblogs.comysoceanp7476379.html目录1、AOP什么?2、需求3、解决办法1:使用静态代理4 ... [详细]
  • 开机自启动的几种方式
    0x01快速自启动目录快速启动目录自启动方式源于Windows中的一个目录,这个目录一般叫启动或者Startup。位于该目录下的PE文件会在开机后进行自启动 ... [详细]
  • 通过使用Sqoop导入工具,可以精确控制并高效地将表数据的特定子集导入到HDFS中。具体而言,可以通过在导入命令中添加WHERE子句来指定所需的数据范围,从而在数据库服务器上执行相应的SQL查询,并将查询结果高效地存储到HDFS中。这种方法不仅提高了数据导入的灵活性,还确保了数据的准确性和完整性。 ... [详细]
  • 在JavaWeb开发中,文件上传是一个常见的需求。无论是通过表单还是其他方式上传文件,都必须使用POST请求。前端部分通常采用HTML表单来实现文件选择和提交功能。后端则利用Apache Commons FileUpload库来处理上传的文件,该库提供了强大的文件解析和存储能力,能够高效地处理各种文件类型。此外,为了提高系统的安全性和稳定性,还需要对上传文件的大小、格式等进行严格的校验和限制。 ... [详细]
  • 在 Axublog 1.1.0 版本的 `c_login.php` 文件中发现了一个严重的 SQL 注入漏洞。该漏洞允许攻击者通过操纵登录请求中的参数,注入恶意 SQL 代码,从而可能获取敏感信息或对数据库进行未授权操作。建议用户尽快更新到最新版本并采取相应的安全措施以防止潜在的风险。 ... [详细]
  • Presto:高效即席查询引擎的深度解析与应用
    本文深入解析了Presto这一高效的即席查询引擎,详细探讨了其架构设计及其优缺点。Presto通过内存到内存的数据处理方式,显著提升了查询性能,相比传统的MapReduce查询,不仅减少了数据传输的延迟,还提高了查询的准确性和效率。然而,Presto在大规模数据处理和容错机制方面仍存在一定的局限性。本文还介绍了Presto在实际应用中的多种场景,展示了其在大数据分析领域的强大潜力。 ... [详细]
  • 微信小程序实现类似微博的无限回复功能,内置云开发数据库支持
    本文详细介绍了如何利用微信小程序实现类似于微博的无限回复功能,并充分利用了微信云开发的数据库支持。文中不仅提供了关键代码片段,还包含了完整的页面代码,方便开发者按需使用。此外,HTML页面中包含了一些示例图片,开发者可以根据个人喜好进行替换。文章还将展示详细的数据库结构设计,帮助读者更好地理解和实现这一功能。 ... [详细]
  • 类加载机制是Java虚拟机运行时的重要组成部分。本文深入解析了类加载过程的第二阶段,详细阐述了从类被加载到虚拟机内存开始,直至其从内存中卸载的整个生命周期。这一过程中,类经历了加载(Loading)、验证(Verification)等多个关键步骤。通过具体的实例和代码示例,本文探讨了每个阶段的具体操作和潜在问题,帮助读者全面理解类加载机制的内部运作。 ... [详细]
  • CSS3 @font-face 字体应用技术解析与实践
    在Web前端开发中,HTML教程和CSS3的结合使得网页设计更加多样化。长期以来,Web设计师受限于“web-safe”字体的选择。然而,CSS3中的`@font-face`规则允许从服务器端加载自定义字体,极大地丰富了网页的视觉效果。通过这一技术,设计师可以自由选择和使用各种字体,提升用户体验和页面美观度。本文将深入解析`@font-face`的实现原理,并提供实际应用案例,帮助开发者更好地掌握这一强大工具。 ... [详细]
author-avatar
小勺年
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有