欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java jsp学生管理系统(1、用户管理+学院管理+学生管理 2、学生\管理员权限区分)

程序员文章站 2022-05-17 19:04:54
...

java jsp 学生信息管理系统

这段时间回顾了下jsp的知识,简单写了个学生管理系统,大概功能有:
1、学生管理、用户管理、学院管理、个人信息
2、权限划分上,实现了不同角色不同权限:普通用户、学生只有浏览权限,管理员可以增删改查

实现过程

整体代码使用了简单的分层,实体类层(以及dao层)、service逻辑层、controller控制层。

一共有三个实体类:用户类、学生类、学院类

public class User {
	
	private static final long serialVersionUID = 1L;
	private String id;
	private String username;		// 用户名
	private String password;		// 密码
	private String pic;		// 头像
	private String role;		// 角色
	private String type;   //类型
	
	public User() {
		super();
	}

	public User(String id){
		this.id = id;
	}
	
	public String getId() {
		return id;
	}


	public void setId(String id) {
		this.id = id;
	}
	

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}
	
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
	public String getPic() {
		return pic;
	}

	public void setPic(String pic) {
		this.pic = pic;
	}
	
	public String getRole() {
		return role;
	}

	public void setRole(String role) {
		this.role = role;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
	
	
	
}
public class Student {
	
	private static final long serialVersionUID = 1L;
	private String id;
	private String name;		// 姓名
	private Integer age;		// 年龄
	private String sex;		// 性别
	private String address;		// 家庭住址
	private String tel;		// 家庭电话
	private String phone;		// 手机号码
	private String code;		// 身份证号码
	private String content;		// content
	private String classId;		// 班级编号
	private String pic;
	private String cname;
	private String collegeId;  //学院编号
	
	
	public String getCname() {
		return cname;
	}

	public void setCname(String cname) {
		this.cname = cname;
	}

	public String getPic() {
		return pic;
	}

	public void setPic(String pic) {
		this.pic = pic;
	}

	public Student() {
		super();
	}

	public Student(String id){
		this.id = id;
	}
	
	public String getId() {
		return id;
	}


	public void setId(String id) {
		this.id = id;
	}
	

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}
	
	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}
	
	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}
	
	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}
	
	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}
	
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}
	
	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}
	
	public String getClassId() {
		return classId;
	}

	public void setClassId(String classId) {
		this.classId = classId;
	}

	public String getCollegeId() {
		return collegeId;
	}

	public void setCollegeId(String collegeId) {
		this.collegeId = collegeId;
	}
	
	
}
public class College {
	
	private static final long serialVersionUID = 1L;
	private String id;
	private String name;		// 学院名称
	private String locate;		// 建筑位置
	
	public College() {
		super();
	}

	public College(String id){
		this.id = id;
	}
	
	public String getId() {
		return id;
	}


	public void setId(String id) {
		this.id = id;
	}
	

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getLocate() {
		return locate;
	}

	public void setLocate(String locate) {
		this.locate = locate;
	}
		
}

dao层:分别用来操作user、student、college的数据表

public class StudentDao {

	
	/**
	 * 添加
	 * @param con
	 * @param student
	 * @return
	 * @throws Exception
	 */
	public int add(Connection con,Student student)throws Exception{
		student.setId(UUID.randomUUID().toString().replace("-", ""));
		String sql="insert into db_student values(?,?,?,?,?,?,?,?,?,?,?)";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1,student.getId());
		pstmt.setString(2,student.getName());
		pstmt.setInt(3,student.getAge());
		pstmt.setString(4,student.getSex());
		pstmt.setString(5,student.getAddress());
		pstmt.setString(6,student.getTel());
		pstmt.setString(7,student.getPhone());
		pstmt.setString(8,student.getCode());
		pstmt.setString(9,student.getContent());
		pstmt.setString(10,student.getPic());
//		pstmt.setString(11,student.getClassId());
		pstmt.setString(11,student.getCollegeId());
		return pstmt.executeUpdate();
	}
	
	/**
	 * 删除
	 * @param con
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public int delete(Connection con,String id)throws Exception{
		String sql="delete from db_student where id=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, id);
		return pstmt.executeUpdate();
	}
	
	
	/**
	 * 更新
	 * @param con
	 * @param user
	 * @return
	 * @throws Exception
	 */
	public int update(Connection con,Student student)throws Exception{
		String sql="update db_student set name=?,age=?,sex=?,address=?,tel=?,phone=?,code=?,content=?,pic=?,college_id=? where id = ?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(11,student.getId());
		pstmt.setString(1,student.getName());
		pstmt.setInt(2,student.getAge());
		pstmt.setString(3,student.getSex());
		pstmt.setString(4,student.getAddress());
		pstmt.setString(5,student.getTel());
		pstmt.setString(6,student.getPhone());
		pstmt.setString(7,student.getCode());
		pstmt.setString(8,student.getContent());
		pstmt.setString(9,student.getPic());
//		pstmt.setString(10,student.getClassId());
		pstmt.setString(10,student.getCollegeId());
		return pstmt.executeUpdate();
	}
	
	
	/**
	 * 查询所有
	 * @param con
	 * @param student
	 * @return
	 * @throws Exception
	 */
	public List<Student> list(Connection con,Student student,Page<Student> page)throws Exception{
		List<Student> list = new ArrayList<>();
		Student entity=null;
		StringBuffer sqlBuffer = new StringBuffer();
		sqlBuffer.append("select a.*,b.name as cname from db_student a left join db_college b on b.id = a.college_id where 1=1");
		//拼接分页条件
			String name =  student.getName();
			if(name != null && name !=""){
				sqlBuffer.append(" and a.name = '"+name+"'");
			}
			
			String collegeId =  student.getCollegeId();
			if(collegeId != null && collegeId !=""){
				sqlBuffer.append(" and a.class_id = '"+collegeId+"'");
			}
			
		
		
		//拼装分页参数
		sqlBuffer.append(" limit "+((page.getPageNo()-1)*page.getPageSize())+","+page.getPageSize());
		
		String sql=sqlBuffer.toString();
		PreparedStatement pstmt=con.prepareStatement(sql);
		ResultSet rs=pstmt.executeQuery();
		while(rs.next()){
			entity = new Student();
			entity.setId(rs.getString("id"));
			entity.setName(rs.getString("name"));
			entity.setAge(rs.getInt("age"));
			entity.setSex(rs.getString("sex"));
			entity.setAddress(rs.getString("address"));
			entity.setTel(rs.getString("tel"));
			entity.setPhone(rs.getString("phone"));
			entity.setCode(rs.getString("code"));
			entity.setContent(rs.getString("content"));
			entity.setPic(rs.getString("pic"));
//			entity.setClassId(rs.getString("class_id"));
			entity.setClassId(rs.getString("college_id"));
			entity.setCname(rs.getString("cname"));
			list.add(entity);
		}
		return list;
	}
	
	/**
	 * id查询
	 * @param con
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public Student getById(Connection con,String id)throws Exception{
		Student student=null;
		String sql="select * from db_student where id = ?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, id);
		ResultSet rs=pstmt.executeQuery();
		if(rs.next()){
			student=new Student();
			student.setId(rs.getString("id"));
			student.setName(rs.getString("name"));
			student.setAge(rs.getInt("age"));
			student.setSex(rs.getString("sex"));
			student.setAddress(rs.getString("address"));
			student.setTel(rs.getString("tel"));
			student.setPhone(rs.getString("phone"));
			student.setCode(rs.getString("code"));
			student.setContent(rs.getString("content"));
			student.setPic(rs.getString("pic"));
//			student.setClassId(rs.getString("class_id"));
			student.setClassId(rs.getString("college_id"));
		}
		return student;
	}
	
	//获取总数 分页使用
	public int count(Connection con,Student student)throws Exception{
		int count = 0;
		StringBuffer sqlBuffer = new StringBuffer();
		sqlBuffer.append("select count(*) as count from db_student where 1=1");
		//拼接分页条件
			String name =  student.getName();
			if(name != null && name !=""){
				sqlBuffer.append(" and name = '"+name+"'");
			}
			
			String collegeId =  student.getCollegeId();
			if(collegeId != null && collegeId !=""){
				sqlBuffer.append(" and college_id = '"+collegeId+"'");
			}
			
		
		String sql=sqlBuffer.toString();
		PreparedStatement pstmt=con.prepareStatement(sql);
		ResultSet rs=pstmt.executeQuery();
		while(rs.next()){
			count = rs.getInt("count");
		}
		return count;
	}
	
	
}
public class CollegeDao {

	
	/**
	 * 添加
	 * @param con
	 * @param college
	 * @return
	 * @throws Exception
	 */
	public int add(Connection con,College college)throws Exception{
		college.setId(UUID.randomUUID().toString().replace("-", ""));
		String sql="insert into db_college values(?,?,?)";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1,college.getId());
		pstmt.setString(2,college.getName());
		pstmt.setString(3,college.getLocate());
		return pstmt.executeUpdate();
	}
	
	/**
	 * 删除
	 * @param con
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public int delete(Connection con,String id)throws Exception{
		String sql="delete from db_college where id=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, id);
		return pstmt.executeUpdate();
	}
	
	
	/**
	 * 更新
	 * @param con
	 * @param user
	 * @return
	 * @throws Exception
	 */
	public int update(Connection con,College college)throws Exception{
		String sql="update db_college set name=?,locate=? where id = ?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(3,college.getId());
		pstmt.setString(1,college.getName());
		pstmt.setString(2,college.getLocate());
		return pstmt.executeUpdate();
	}
	
	
	/**
	 * 查询所有
	 * @param con
	 * @param grade
	 * @return
	 * @throws Exception
	 */
	public List<College> list(Connection con,College college,Page<College> page)throws Exception{
		List<College> list = new ArrayList<>();
		College entity=null;
		StringBuffer sqlBuffer = new StringBuffer();
		sqlBuffer.append("select * from db_college where 1=1");
		//拼接分页条件
			String name =  college.getName();
			if(name != null && name !=""){
				sqlBuffer.append(" and name = '"+name+"'");
			}
			
			String locate =  college.getLocate();
			if(locate != null && locate !=""){
				sqlBuffer.append(" and locate = '"+locate+"'");
			}
			
		
		
		//拼装分页参数
		sqlBuffer.append(" limit "+((page.getPageNo()-1)*page.getPageSize())+","+page.getPageSize());
		
		String sql=sqlBuffer.toString();
		PreparedStatement pstmt=con.prepareStatement(sql);
		ResultSet rs=pstmt.executeQuery();
		while(rs.next()){
			entity = new College();
			entity.setId(rs.getString("id"));
			entity.setName(rs.getString("name"));
			entity.setLocate(rs.getString("locate"));
			list.add(entity);
		}
		return list;
	}
	
	/**
	 * id查询
	 * @param con
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public College getById(Connection con,String id)throws Exception{
		College college=null;
		String sql="select * from db_college where id = ?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, id);
		ResultSet rs=pstmt.executeQuery();
		if(rs.next()){
			college=new College();
			college.setId(rs.getString("id"));
			college.setName(rs.getString("name"));
			college.setLocate(rs.getString("locate"));
		}
		return college;
	}
	
	//获取总数 分页使用
	public int count(Connection con,College college)throws Exception{
		int count = 0;
		StringBuffer sqlBuffer = new StringBuffer();
		sqlBuffer.append("select count(*) as count from db_college where 1=1");
		//拼接分页条件
			String name =  college.getName();
			if(name != null && name !=""){
				sqlBuffer.append(" and name = '"+name+"'");
			}
			
			String locate =  college.getLocate();
			if(locate != null && locate !=""){
				sqlBuffer.append(" and locate = '"+locate+"'");
			}
			
		
		String sql=sqlBuffer.toString();
		PreparedStatement pstmt=con.prepareStatement(sql);
		ResultSet rs=pstmt.executeQuery();
		while(rs.next()){
			count = rs.getInt("count");
		}
		return count;
	}
	
	
}
public class UserDao {

	
	/**
	 * 添加
	 * @param con
	 * @param user
	 * @return
	 * @throws Exception
	 */
	public int add(Connection con,User user)throws Exception{
		user.setId(UUID.randomUUID().toString().replace("-", ""));
		String sql="insert into db_user values(?,?,?,?,?,?)";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1,user.getId());
		pstmt.setString(2,user.getUsername());
		pstmt.setString(3,user.getPassword());
		pstmt.setString(4,user.getPic());
		pstmt.setString(5,user.getRole());
		pstmt.setString(6,user.getType());
		return pstmt.executeUpdate();
	}
	
	/**
	 * 删除
	 * @param con
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public int delete(Connection con,String id)throws Exception{
		String sql="delete from db_user where id=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, id);
		return pstmt.executeUpdate();
	}
	
	
	/**
	 * 更新
	 * @param con
	 * @param user
	 * @return
	 * @throws Exception
	 */
	public int update(Connection con,User user)throws Exception{
		String sql="update db_user set username=?,password=?,pic=?,role=? where id = ?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(5,user.getId());
		pstmt.setString(1,user.getUsername());
		pstmt.setString(2,user.getPassword());
		pstmt.setString(3,user.getPic());
		pstmt.setString(4,user.getRole());
		return pstmt.executeUpdate();
	}
	
	
	/**
	 * 查询所有
	 * @param con
	 * @param user
	 * @return
	 * @throws Exception
	 */
	public List<User> list(Connection con,User user,Page<User> page)throws Exception{
		List<User> list = new ArrayList<>();
		User entity=null;
		StringBuffer sqlBuffer = new StringBuffer();
		sqlBuffer.append("select * from db_user where 1=1");
		//拼接分页条件
			String username =  user.getUsername();
			if(username != null && username !=""){
				sqlBuffer.append(" and username = '"+username+"'");
			}
			
		
		
		//拼装分页参数
		sqlBuffer.append(" limit "+((page.getPageNo()-1)*page.getPageSize())+","+page.getPageSize());
		
		String sql=sqlBuffer.toString();
		PreparedStatement pstmt=con.prepareStatement(sql);
		ResultSet rs=pstmt.executeQuery();
		while(rs.next()){
			entity = new User();
			entity.setId(rs.getString("id"));
			entity.setUsername(rs.getString("username"));
			entity.setPassword(rs.getString("password"));
			entity.setPic(rs.getString("pic"));
			entity.setRole(rs.getString("role"));
			list.add(entity);
		}
		return list;
	}
	
	/**
	 * id查询
	 * @param con
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public User getById(Connection con,String id)throws Exception{
		User user=null;
		String sql="select * from db_user where id = ?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, id);
		ResultSet rs=pstmt.executeQuery();
		if(rs.next()){
			user=new User();
			user.setId(rs.getString("id"));
			user.setUsername(rs.getString("username"));
			user.setPassword(rs.getString("password"));
			user.setPic(rs.getString("pic"));
			user.setRole(rs.getString("role"));
		}
		return user;
	}
	
	//获取总数 分页使用
	public int count(Connection con,User user)throws Exception{
		int count = 0;
		StringBuffer sqlBuffer = new StringBuffer();
		sqlBuffer.append("select count(*) as count from db_user where 1=1");
		//拼接分页条件
			String username =  user.getUsername();
			if(username != null && username !=""){
				sqlBuffer.append(" and username = '"+username+"'");
			}
			
		
		String sql=sqlBuffer.toString();
		PreparedStatement pstmt=con.prepareStatement(sql);
		ResultSet rs=pstmt.executeQuery();
		while(rs.next()){
			count = rs.getInt("count");
		}
		return count;
	}
	
	
}
public class LoginDao {

	
	/**
	 * 用户登录
	 * @param con
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public User login(Connection con,String username,String password, String type)throws Exception{
		User user=null;
		String sql="select * from db_user where username = ? and password=? and type=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, username);
		pstmt.setString(2, password);
		pstmt.setString(3, type);
		ResultSet rs=pstmt.executeQuery();
		if(rs.next()){
			user = new User();
			user.setId(rs.getString("id"));
			user.setUsername(rs.getString("username"));
			user.setPassword(rs.getString("password"));
			user.setPic(rs.getString("pic"));
			user.setRole(rs.getString("role"));
			user.setType(rs.getString("type"));
		}
		return user;
	}
	
	
	public User checkUsername(Connection con,String username)throws Exception{
		User user=null;
		String sql="select * from db_user where username = ?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, username);
		ResultSet rs=pstmt.executeQuery();
		if(rs.next()){
			user = new User();
			user.setId(rs.getString("id"));
			user.setUsername(rs.getString("username"));
			user.setPassword(rs.getString("password"));
			user.setPic(rs.getString("pic"));
			user.setRole(rs.getString("role"));
		}
		return user;
	} 
	
}

service层(处理逻辑):

/**
 * 学院DAO接口
 *
 */
public class CollegeServiceImpl  implements CollegeService  {
	
	CollegeDao collegeDao = new CollegeDao();
	
	@Override
	public int add(College college) {
		try {
			Connection con = DbUtil.getCon();
			Integer result =collegeDao.add(con, college);
			DbUtil.closeCon(con);
			return result;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}

	@Override
	public int delete(String id) {
		try {
			Connection con = DbUtil.getCon();
			int delete = collegeDao.delete(con, id);
			DbUtil.closeCon(con);
			return delete;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}

	@Override
	public int update(College college) {
		try {
			Connection con = DbUtil.getCon();
			int update = collegeDao.update(con, college);
			DbUtil.closeCon(con);
			return update;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}

	@Override
	public Page<College> page(College college, Page<College> page) {
		try {
			Connection con = DbUtil.getCon();
			int count = collegeDao.count(con,college);
			page.setCount(count);
			page.setPrev(page.getPageNo()-1);
			page.setNext(page.getPageNo() + 1);// 下一页
			page.setLast((count - 1) / page.getPageSize() + 1);// 总也数
			List<College> list = collegeDao.list(con, college, page);
			page.setList(list);
			DbUtil.closeCon(con);
			return page;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public College getById(String id) {
		try {
			Connection con = DbUtil.getCon();
			College college = collegeDao.getById(con, id);
			DbUtil.closeCon(con);
			return college;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
		
}

这一层就贴这一个吧,其他的与这个逻辑相同,可以参照着写

controller控制层,也只贴下CollegeController.java:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
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 org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

import com.student.info.bean.College;
import com.student.info.dao.CollegeDao;
import com.student.info.service.CollegeService;
import com.student.info.service.impl.CollegeServiceImpl;
import com.student.utils.Page;

@WebServlet("/college")
public class CollegeController extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	CollegeDao collegeDao=new CollegeDao();
	CollegeService collegeService = new CollegeServiceImpl();
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String method = request.getParameter("method");
		if ("add".equals(method)) {
			add(request,response);
		}else if ("delete".equals(method)) {
			delete(request, response);
		}else if ("list".equals(method)) {
			list(request, response);
		}else if ("update".equals(method)) {
			update(request, response);
		}else if ("form".equals(method)) {
			form(request, response);
		}else if ("save".equals(method)) {
			save(request, response);
		}
		
	}
	
	//添加
	private void add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String contextPath = request.getServletContext().getContextPath();

		String name = request.getParameter("name");
		String locate = request.getParameter("locate");
		College college = new College();
		college.setName(name);
		college.setLocate(locate);
		collegeService.add(college);
		response.sendRedirect(contextPath+"/college?method=list");
	}
	
	//添加保存
	protected void save(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String contextPath = request.getServletContext().getContextPath();
		
		College college = new College();
		 //得到上传文件的保存目录,将上传的文件存放于WEB-INF目录下,不允许外界直接访问,保证上传文件的安全
        String savePath = this.getServletContext().getRealPath("/upload");
        File file = new File(savePath);
        //判断上传文件的保存目录是否存在
        if (!file.exists() && !file.isDirectory()) {
            System.out.println(savePath+"目录不存在,需要创建");
            //创建目录
            file.mkdir();
        }
        //消息提示
        String msg = "";
        try{
            //使用Apache文件上传组件处理文件上传步骤:
            //1、创建一个DiskFileItemFactory工厂
            DiskFileItemFactory factory = new DiskFileItemFactory();
            //2、创建一个文件上传解析器
            ServletFileUpload upload = new ServletFileUpload(factory);
             //解决上传文件名的中文乱码
            upload.setHeaderEncoding("UTF-8"); 
            //3、判断提交上来的数据是否是上传表单的数据
            if(!ServletFileUpload.isMultipartContent(request)){
                //按照传统方式获取数据
                return;
            }
            //4、使用ServletFileUpload解析器解析上传数据,解析结果返回的是一个List<FileItem>集合,每一个FileItem对应一个Form表单的输入项
            List<FileItem> list = upload.parseRequest(request);
            for(FileItem item : list){
                //如果fileitem中封装的是普通输入项的数据
                if(item.isFormField()){
                    String name = item.getFieldName();
                     //解决普通输入项的数据的中文乱码问题
					if ("id".endsWith(name)) {
                    	if (item.getString("UTF-8")!=null && item.getString("UTF-8")!="") {
                    		college.setId(item.getString("UTF-8"));
						}
					}
					if ("name".endsWith(name)) {
						college.setName(item.getString("UTF-8"));
					}
					if ("locate".endsWith(name)) {
						college.setLocate(item.getString("UTF-8"));
					}
                    
                }else{//如果fileitem中封装的是上传文件
                    //得到上传的文件名称,
                    String filename = item.getName();
                    System.out.println(filename);
                    if(filename==null || filename.trim().equals("")){
                        continue;
                    }
                    //注意:不同的浏览器提交的文件名是不一样的,有些浏览器提交上来的文件名是带有路径的,如:  c:\a\b\1.txt,而有些只是单纯的文件名,如:1.txt
                    //处理获取到的上传文件的文件名的路径部分,只保留文件名部分
                    filename = filename.substring(filename.lastIndexOf("\\")+1);
                    //获取item中的上传文件的输入流
                    InputStream in = item.getInputStream();
                    //创建一个文件输出流
                    FileOutputStream out = new FileOutputStream(savePath + "\\" + filename);
                    //创建一个缓冲区
                    byte buffer[] = new byte[1024];
                    //判断输入流中的数据是否已经读完的标识
                    int len = 0;
                    //循环将输入流读入到缓冲区当中,(len=in.read(buffer))>0就表示in里面还有数据
                    while((len=in.read(buffer))>0){
                        //使用FileOutputStream输出流将缓冲区的数据写入到指定的目录(savePath + "\\" + filename)当中
                        out.write(buffer, 0, len);
                    }
                    //关闭输入流
                    in.close();
                    //关闭输出流
                    out.close();
                    //删除处理文件上传时生成的临时文件
                    item.delete();
 					msg = "文件上传成功!";
                    
                }
            }
            if (college.getId()!=null && !"".equals(college.getId())) {
    			collegeService.update(college);
    		}else{
    			collegeService.add(college);
    		}
    		response.sendRedirect(contextPath+"/college?method=list");
        }catch (Exception e) {
            msg= "文件上传失败!";
            e.printStackTrace();
            request.setAttribute("msg",msg);
            request.getRequestDispatcher("/views/info/collegeForm.jsp").forward(request, response);
        }
	}
	
	//删除
	private void delete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String contextPath = request.getServletContext().getContextPath();
		String id = request.getParameter("id");
		collegeService.delete(id);
		response.sendRedirect(contextPath+"/college?method=list");
	}
	
	//修改
	private void update(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String id = request.getParameter("id");
		String name = request.getParameter("name");
		String locate = request.getParameter("locate");
		College college = new College();
		college.setId(id);
		college.setName(name);
		college.setLocate(locate);
		collegeService.update(college);
		request.setAttribute("college", college);
		request.getRequestDispatcher("/views/info/collegeForm.jsp").forward(request, response);
	}
	
	//列表查询
	private void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.err.println("---开始查询---");
		College college = new College();
		//分页有关
		Page<College> page = new Page<College>();
		//设置查询页
		String pageNoStr = request.getParameter("pageNo");
		if (pageNoStr != null && pageNoStr != "") {
			page.setPageNo(Integer.parseInt(pageNoStr));
		}
		//设置查询条件
		String name = request.getParameter("name");
		if (name != null && name != "") {
			college.setName(name);
			request.setAttribute("name", name);
		}
		String locate = request.getParameter("locate");
		if (locate != null && locate != "") {
			college.setLocate(locate);
			request.setAttribute("locate", locate);
		}
		
		page = collegeService.page(college, page);
		request.setAttribute("page", page);
		request.getRequestDispatcher("/views/info/collegeList.jsp").forward(request, response);
	}
	
	//form跳转页面
	private void form(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String id = request.getParameter("id");
		College college = new College();
		if (id!=null && id!="") {
			college = collegeService.getById(id);
		}
		request.setAttribute("college", college);
		request.getRequestDispatcher("/views/info/collegeForm.jsp").forward(request, response);
	}
	
}

对了,缺少sql,我把sql也贴出来(里面包含了初始化的一些数据):

/*
Navicat MySQL Data Transfer

Source Server         : localhost_3306
Source Server Version : 50723
Source Host           : localhost:3306
Source Database       : webstudent1

Target Server Type    : MYSQL
Target Server Version : 50723
File Encoding         : 65001

Date: 2020-07-09 21:29:12
*/

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for db_class
-- ----------------------------
DROP TABLE IF EXISTS `db_class`;
CREATE TABLE `db_class` (
  `id` varchar(64) NOT NULL COMMENT '编号',
  `name` varchar(64) DEFAULT NULL COMMENT '班级名称',
  `content` text COMMENT '班级介绍',
  `teacher` varchar(64) DEFAULT NULL COMMENT '班主任',
  `tel` varchar(64) DEFAULT NULL COMMENT '班主任电话',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of db_class
-- ----------------------------
INSERT INTO `db_class` VALUES ('0f4821bf4a7d4b76b6a8cc7be00531db', '一年级', '一年级', '李老师', '17823212222');
INSERT INTO `db_class` VALUES ('7064fe6a918a44b892bc5e1946b10238', '三年级', '三年级', '牛老师', '17823212222');
INSERT INTO `db_class` VALUES ('8ff3cda9ba9841dd87433d23015b8b5f', '二年级', '呵呵呵', '得老师', '17823212222');
INSERT INTO `db_class` VALUES ('9a51b9230886403fa6f2aa674fbaf9ed', '计算机一班', '测试', '小李老师', '15878784520');

-- ----------------------------
-- Table structure for db_college
-- ----------------------------
DROP TABLE IF EXISTS `db_college`;
CREATE TABLE `db_college` (
  `id` varchar(64) NOT NULL COMMENT '编号',
  `name` varchar(64) DEFAULT NULL COMMENT '班级名称',
  `locate` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of db_college
-- ----------------------------
INSERT INTO `db_college` VALUES ('1', '计算机学院', '11号楼');
INSERT INTO `db_college` VALUES ('2', '材料学院', '2号楼');
INSERT INTO `db_college` VALUES ('c64c91db35ac4a84a4e9e2b1d279e4ec', '理学院', '7号楼');
INSERT INTO `db_college` VALUES ('d1548e5235c547358c862fa8b15775de', '文学院', '4号楼');

-- ----------------------------
-- Table structure for db_student
-- ----------------------------
DROP TABLE IF EXISTS `db_student`;
CREATE TABLE `db_student` (
  `id` varchar(64) NOT NULL COMMENT '编号',
  `name` varchar(64) DEFAULT NULL COMMENT '姓名',
  `age` int(11) DEFAULT NULL COMMENT '年龄',
  `sex` varchar(64) DEFAULT NULL COMMENT '性别',
  `address` varchar(255) DEFAULT NULL COMMENT '家庭住址',
  `tel` varchar(64) DEFAULT NULL COMMENT '家庭电话',
  `phone` varchar(64) DEFAULT NULL COMMENT '手机号码',
  `code` varchar(64) DEFAULT NULL COMMENT '身份证号码',
  `content` text COMMENT 'content',
  `pic` varchar(255) DEFAULT NULL COMMENT '头像',
  `college_id` varchar(64) DEFAULT NULL COMMENT '学院编号',
  PRIMARY KEY (`id`),
  KEY `class_id` (`college_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of db_student
-- ----------------------------
INSERT INTO `db_student` VALUES ('6ab3b6028e2244ae8b732337cf5cbd2c', '小李2', '23', '男', '北京', '1845362721', 'aaa@qq.com', '2039', 'af', null, '2');
INSERT INTO `db_student` VALUES ('9d6f05fdb9a3420fb64b551bc45494a0', '小王', '24', '男', '北京', '1845362721', 'aaa@qq.com', '5698', 'af', null, 'd1548e5235c547358c862fa8b15775de');
INSERT INTO `db_student` VALUES ('accb0844809b4e85a1513008354ab4c1', '小李', '23', '男', '北京', '1845362721', 'aaa@qq.com', '看电影', '124235', null, '1');
INSERT INTO `db_student` VALUES ('dfeeba837d61404e96c3f112997007d0', '章子', '23', '男', '北京', '1845362721', 'aaa@qq.com', '7465', 'afsa', null, 'd1548e5235c547358c862fa8b15775de');

-- ----------------------------
-- Table structure for db_user
-- ----------------------------
DROP TABLE IF EXISTS `db_user`;
CREATE TABLE `db_user` (
  `id` varchar(64) NOT NULL COMMENT 'ID',
  `username` varchar(64) DEFAULT NULL COMMENT '用户名',
  `password` varchar(255) DEFAULT NULL COMMENT '密码',
  `pic` varchar(255) DEFAULT NULL COMMENT '头像',
  `role` varchar(100) DEFAULT NULL COMMENT '角色',
  `type` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of db_user
-- ----------------------------
INSERT INTO `db_user` VALUES ('0c4910f52539481ea56e7696adb6aa80', '用户2', '123456', null, '123456', '2');
INSERT INTO `db_user` VALUES ('153df7fb21044639b2d2006fa9bb8871', '小王1', '123456', null, '123456', '0');
INSERT INTO `db_user` VALUES ('1694c6b8a1dd4ad0a7d0c7f5173c8c4e', 'test10', '123456', null, 'test1', '0');
INSERT INTO `db_user` VALUES ('39e02cffc9be4fc7b60076dd33efd252', 'root', '123456', null, '李斯2', '0');
INSERT INTO `db_user` VALUES ('63b0cc5f83194860bde04a9d87cefb52', '李四', '123456', null, '李四', '0');
INSERT INTO `db_user` VALUES ('8637d34e157f4244bc087f0d0a66ebb2', 'admin', '123456', null, '管理员', '1');
INSERT INTO `db_user` VALUES ('8db63a33d3964e69869852099e33b023', '用户3', '123456', null, '用户3', '2');
INSERT INTO `db_user` VALUES ('a3585c69a8da4973a54ecbed06f0f0a6', 'test12', '123456', null, '学生12', '0');
INSERT INTO `db_user` VALUES ('bcc69747173a4725ac5452ba1482eb7b', 'zhangsan', '123456', null, '123456', '0');
INSERT INTO `db_user` VALUES ('c996844be05c4ca88a6f8c552efd7f97', '小何', '123456', null, '123456', '0');
INSERT INTO `db_user` VALUES ('e5e72dd0bfd648eaa61119b7877862b3', 'zs1', '123456', null, '123456', '0');
SET FOREIGN_KEY_CHECKS=1;

系统运行

1、登录页面:分为用户、学生、管理员三种用户登录
java jsp学生管理系统(1、用户管理+学院管理+学生管理 2、学生\管理员权限区分)
2、管理员登录页面:
java jsp学生管理系统(1、用户管理+学院管理+学生管理 2、学生\管理员权限区分)
可以进行用户、学生、学院的增删改查(其他两个模块的页面布局一样)

3、学生和用户登录:
java jsp学生管理系统(1、用户管理+学院管理+学生管理 2、学生\管理员权限区分)
只能浏览,不能进行其他操作

4、如果是学生和管理员登录都可以修改个人信息:
java jsp学生管理系统(1、用户管理+学院管理+学生管理 2、学生\管理员权限区分)

写在最后

技术有限,时间有限,目前只能做到这里,如果有什么建议,可以交流:3459067873