javaweb(servlet)+jsp+Mysql实现的简单相册管理系统(功能包含登录、管理首页、添加图片、分类管理、修改密码、图片详情等)

javaweb(servlet)+jsp+Mysql实现的简单相册管理系统

本系统是一个简单的相册管理系统,可以在线管理本地相册,实现图片的预览和管理。
(文末查看完整源码)

实现功能截图

登录
在这里插入图片描述添加图片

在这里插入图片描述
添加分类
在这里插入图片描述
首页
在这里插入图片描述
图片详情
在这里插入图片描述

在这里插入图片描述

系统功能

本系统实现了以下功能:
1、登录
2、管理首页
3、添加图片
4、分类管理
5、修改密码
6、图片详情
7、退出登录

使用技术

数据库:mysql
开发工具:Idea(Myeclispe、Eclipse也可以)
知识点:javaweb(servlet+jsp)

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

代码

java端
实体类
Photo.java

package com.fsq.beans;

public class Photo {

	private int id = 0;
	private String name;
	private String path = "";
	private int dianji ;
	private String contentTime = "";
	private String shuoming;
	private int lid;	
	private int count;
	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 getPath() {
		return path;
	}
	public void setPath(String path) {
		this.path = path;
	}
	public int getDianji() {
		return dianji;
	}
	public void setDianji(int dianji) {
		this.dianji = dianji;
	}
	public String getContentTime() {
		return contentTime;
	}
	public void setContentTime(String contentTime) {
		this.contentTime = contentTime;
	}
	public String getShuoming() {
		return shuoming;
	}
	public void setShuoming(String shuoming) {
		this.shuoming = shuoming;
	}
	public int getLid() {
		return lid;
	}
	public void setLid(int lid) {
		this.lid = lid;
	}
	public int getCount() {
		return count;
	}
	public void setCount(int count) {
		this.count = count;
	}
	
	
}

Dao层
PhotoDAO.java

package com.fsq.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 com.fsq.beans.Photo;
import com.fsq.util.JdbcUtil;

public class PhotoDAO {

	public List<Photo> getAllPhotos() throws SQLException {
		List<Photo> photoList = new ArrayList<Photo>();
		String sql = "select * from photo";
		Connection conn = JdbcUtil.getConnection();
		Statement stmt = null;
		ResultSet rs = null;
		try {
			stmt = conn.createStatement();
			rs = stmt.executeQuery(sql);
			while (rs.next()) {
				Photo photo = new Photo();
				photo.setId(rs.getInt("id"));
				photo.setName(rs.getString("name"));
				photo.setPath(rs.getString("path"));
				photo.setDianji(rs.getInt("dianji"));
				photo.setContentTime(rs.getString("contenttime"));
				photo.setShuoming(rs.getString("shuoming"));
				photo.setLid(rs.getInt("lid"));
				photoList.add(photo);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw e;
		} finally {
			JdbcUtil.close(rs, null);
			JdbcUtil.close();
		}
		return photoList;
	}

	public void delete(Photo photo) throws SQLException {
		Connection conn = JdbcUtil.getConnection();
		PreparedStatement ps = null;
		String sql = "delete  from photo where id=?";

		try {
			ps = conn.prepareStatement(sql);
			ps.setInt(1, photo.getId());
			ps.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
			throw e;
		} finally {
			JdbcUtil.close(null, ps);
			JdbcUtil.close();
		}
	}

	public boolean updateDianJi(Photo photo) throws SQLException {
		boolean flag = false;
		PreparedStatement ps = null;
		String sql = "UPDATE photo SET dianji=dianji+1 where id=?";
		try {
			Connection conn = JdbcUtil.getConnection();
			ps = conn.prepareStatement(sql);
			ps.setInt(1, photo.getId());
			int n = ps.executeUpdate();
			if (n != 0) {
				flag = true;
			} else {
				flag = false;
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw e;
		} finally {
			JdbcUtil.close(null, ps);
			JdbcUtil.close();
		}
		return flag;
	}

	public void update(Photo photo) throws SQLException {
		Connection conn = JdbcUtil.getConnection();
		PreparedStatement ps = null;
		String sql = "update photo set name=?,shuoming=?,lid=? where id=?";
		try {
			ps = conn.prepareStatement(sql);
			ps.setString(1, photo.getName());
			ps.setString(2, photo.getShuoming());
			ps.setInt(3, photo.getLid());
			ps.setInt(4, photo.getId());
			ps.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
			throw e;
		} finally {
			JdbcUtil.close(null, ps);
			JdbcUtil.close();
		}
	}

	public List<Photo> getAllPhotosByClassId(int id) throws SQLException {
		List<Photo> photoList = new ArrayList<Photo>();
		String sql = "select id,name,path,dianji,shuoming from photo where lid=?";
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			Connection conn = JdbcUtil.getConnection();
			ps = conn.prepareStatement(sql);
			ps.setInt(1, id);
			rs = ps.executeQuery();
			while (rs.next()) {
				Photo photo = new Photo();
				photo.setId(rs.getInt(1));
				photo.setName(rs.getString(2));
				photo.setPath(rs.getString(3));
				photo.setDianji(rs.getInt(4));
				photo.setShuoming(rs.getString(5));
				photoList.add(photo);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw e;
		} finally {
			JdbcUtil.close(rs, ps);
			JdbcUtil.close();
		}
		return photoList;
	}

	public Photo getPhotoById(int id) throws SQLException {
		String sql = "select id,name,path,contentTime,shuoming,lid from photo where id=?";
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			Connection conn = JdbcUtil.getConnection();
			ps = conn.prepareStatement(sql);
			ps.setInt(1, id);
			rs = ps.executeQuery();
			while (rs.next()) {
				Photo photo = new Photo();
				photo.setId(rs.getInt(1));
				photo.setName(rs.getString(2));
				photo.setPath(rs.getString(3));
				photo.setContentTime(rs.getString(4));
				photo.setShuoming(rs.getString(5));
				photo.setLid(rs.getInt(6));
				return photo;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			JdbcUtil.close(rs, ps);
			JdbcUtil.close();
		}
		return null;
	}

	public boolean insert(Photo photo) throws SQLException {
		Connection conn = null;
		PreparedStatement ps = null;
		try {
			String sql = "insert into photo (name,path,shuoming,contentTime,lid,dianji) values(?,?,?,?,?,0)";
			conn = JdbcUtil.getConnection();
			ps = conn.prepareStatement(sql);
			ps.setString(1, photo.getName());
			ps.setString(2, photo.getPath());
			ps.setString(3, photo.getShuoming());
			ps.setString(4, photo.getContentTime());
			ps.setInt(5, photo.getLid());
			int num = ps.executeUpdate();
			if (num != 0) {
				return true;
			}
			return false;
		} catch (SQLException e) {
			e.printStackTrace();
			throw e;
		} finally {
			JdbcUtil.close(null, ps);
			JdbcUtil.close();
		}
	}

}

servlet类
PhotoServlet.java

package com.fsq.servlet;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
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 javax.servlet.http.HttpSession;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

import com.fsq.beans.Photo;
import com.fsq.beans.PhotoClass;
import com.fsq.beans.PingLun;
import com.fsq.biz.PhotoBiz;
import com.fsq.dao.PhotoClassDAO;
import com.fsq.dao.PhotoDAO;
import com.fsq.dao.PingLunDAO;
import com.fsq.util.ImageUtils;

public class PhotoServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public PhotoServlet() {
		super();
	}

	public void destroy() {
		super.destroy();
	}

	@SuppressWarnings("unused")
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		String toUrl = "";
		String action = request.getParameter("action");
		if ("getAll".equals(action)) { // admin的管理主页面 amain.jsp
			PhotoBiz photoBiz = new PhotoBiz();
			List<Photo> list = null;
			HttpSession session = request.getSession();
			try {
				list = photoBiz.getAllPhotos();
				request.setAttribute("selAllList", list);
				request.getRequestDispatcher("/admin/amain.jsp").forward(
						request, response);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		if ("addPhoto".equals(action)) {
			List<PhotoClass> list = new PhotoClassDAO().getAllClass();
			request.setAttribute("list", list);
			request.getRequestDispatcher("admin/photo_add.jsp").forward(
					request, response);
		}
		if ("getAllClient".equals(action)) { // 客户的登录页面 main.jsp
			PhotoBiz photoBiz = new PhotoBiz();
			List<Photo> list = null;
			HttpSession session = request.getSession();
			try {
				list = photoBiz.getAllPhotos();
				request.setAttribute("selAllList", list);
				request.getRequestDispatcher("main.jsp").forward(request,
						response);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		if ("selOne".equals(action)) {
			try {
				String id = request.getParameter("id");
				String str = request.getParameter("str");
				if ("client".equals(str)) {
					Photo photo = new PhotoDAO().getPhotoById(Integer
							.parseInt(id));
					PhotoDAO photoDAO = new PhotoDAO();
					photoDAO.updateDianJi(photo);
					String pathMax = photo.getPath();
					String s[] = pathMax.split("_min");
					photo.setPath("uploadimg/" + s[0] + s[1]);
					request.setAttribute("photo", photo);
					List<PingLun> pingLunList = new PingLunDAO()
							.searchByPhotoId(Integer.parseInt(id));
					request.setAttribute("pingLunList", pingLunList);
					request.getRequestDispatcher("/admin/photo_one.jsp")
							.forward(request, response);
				} else if ("admin".equals(str)) {
					Photo photo = new PhotoDAO().getPhotoById(Integer
							.parseInt(id));
					String pathMax = photo.getPath();
					String s[] = pathMax.split("_min");
					photo.setPath("uploadimg/" + s[0] + s[1]);
					request.setAttribute("photo", photo);
					List<PingLun> pingLunList = new PingLunDAO()
							.searchByPhotoId(Integer.parseInt(id));
					request.setAttribute("pingLunList", pingLunList);
					request.getRequestDispatcher("/admin/photo_one_pinglun.jsp")
							.forward(request, response);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		if ("toupdate".equals(action)) {
			String id = request.getParameter("id");
			try {
				Photo photo = new PhotoDAO().getPhotoById(Integer.parseInt(id));
				request.setAttribute("photo", photo);
				List<PhotoClass> list = new PhotoClassDAO().getAllClass();
				request.setAttribute("list", list);
				request.getRequestDispatcher("/admin/photo_manager.jsp")
						.forward(request, response);
			} catch (SQLException e) {
				request.setAttribute("msg", "数据库错误");
				request.getRequestDispatcher("/admin/result.jsp").forward(
						request, response);
			}
		}
		if ("update1".equals(action)) {
			String id = request.getParameter("id");
			String name = request.getParameter("name");
			String shuoming = request.getParameter("shuoming");
			String lid = request.getParameter("lid");
			try {
				Photo photo = new PhotoDAO().getPhotoById(Integer.parseInt(id));
				photo.setName(name);
				photo.setShuoming(shuoming);
				photo.setLid(Integer.parseInt(lid));
				new PhotoDAO().update(photo);
				request.setAttribute("msg", "恭喜您,图片信息修改成功");
				request.getRequestDispatcher("/admin/result.jsp").forward(
						request, response);

			} catch (NumberFormatException e) {
				request.setAttribute("msg", "数据格式错误");
				request.getRequestDispatcher("/admin/result.jsp").forward(
						request, response);
				e.printStackTrace();
			} catch (SQLException e) {
				request.setAttribute("msg", "数据库错误");
				request.getRequestDispatcher("/admin/result.jsp").forward(
						request, response);
				e.printStackTrace();
			}
		}
		if ("delete".equals(action)) {
			String id = request.getParameter("id");
			try {
				Photo photo = new PhotoDAO().getPhotoById(Integer.parseInt(id));
				new PhotoDAO().delete(photo);
				request.setAttribute("msg", "恭喜您,图片已成功删除");
				request.getRequestDispatcher("/admin/result.jsp").forward(
						request, response);
			} catch (NumberFormatException e) {
				request.setAttribute("msg", "数据格式错误");
				request.getRequestDispatcher("/admin/result.jsp").forward(
						request, response);
				e.printStackTrace();
			} catch (SQLException e) {
				request.setAttribute("msg", "数据库错误");
				request.getRequestDispatcher("/admin/result.jsp").forward(
						request, response);
				e.printStackTrace();
			}
		}
		if ("seeAllPhotosByClassId".equals(action)) { // 分类查看是 photoa_all.jsp
			String id = request.getParameter("id");
			String num = request.getParameter("num");
			if (Integer.parseInt(num) == 0) {
				request.setAttribute("msg", "对不起该分类下没有文件");
				request.getRequestDispatcher("/admin/result.jsp").forward(
						request, response);
			} else {

				try {
					List<Photo> photoList = new ArrayList<Photo>();
					PhotoDAO photoDAO = new PhotoDAO();
					photoList = photoDAO.getAllPhotosByClassId(Integer
							.parseInt(id));					
					request.setAttribute("photoList", photoList);
					request.getRequestDispatcher("/admin/photo_all.jsp")
							.forward(request, response);
				} catch (NumberFormatException e) {
					request.setAttribute("msg", "数据格式错误");
					request.getRequestDispatcher("/admin/result.jsp").forward(
							request, response);
					e.printStackTrace();
				} catch (SQLException e) {
					request.setAttribute("msg", "数据库错误");
					request.getRequestDispatcher("/admin/result.jsp").forward(
							request, response);
					e.printStackTrace();
				}

			}
		}
		if ("add".equals(action)) {
			boolean flag = false;
			Photo photo = new Photo();
			PhotoDAO photoDAO = new PhotoDAO();
			String msg = "";
			try {
				Calendar calendar = Calendar.getInstance();
				String newfilename = String.valueOf(calendar.getTimeInMillis());
				DiskFileItemFactory factory = new DiskFileItemFactory();
				ServletFileUpload upload = new ServletFileUpload(factory);
				List<?> items = upload.parseRequest(request);
				Iterator<?> iter = items.iterator();
				while (iter.hasNext()) {
					FileItem item = (FileItem) iter.next();
					if (item.isFormField()) {
						String fieldName = item.getFieldName();
						String fieldValue = new String(item.getString("utf-8"));
						if ("shuoming".equals(fieldName)) {
							photo.setShuoming(fieldValue);
						} else if ("name".equals(fieldName)) {
							photo.setName(fieldValue);
						} else if ("lid".equals(fieldName)) {
							photo.setLid(Integer.parseInt(fieldValue));
						}
					} else {
						String fieldName = item.getFieldName();
						String fileName = item.getName();
						String ext = fileName.substring(fileName
								.lastIndexOf('.') + 1);
						String contentType = item.getContentType();
						boolean isInMemory = item.isInMemory();
						long sizeInBytes = item.getSize();
						String saveurl = request.getSession()
								.getServletContext().getRealPath("/")
								+ "uploadimg\\";
						String s = this.getServletContext().getRealPath("/");
						String newfilenamewithext = newfilename + "." + ext;
						File uploadedFile = new File(saveurl
								+ newfilenamewithext);
						item.write(uploadedFile);
						String newfilename_min = ImageUtils.createMinPic(
								saveurl, newfilename, ext);
						photo.setPath(newfilename_min);
						String contenttime = "";
						Date dt = new Date();
						SimpleDateFormat sdf = new SimpleDateFormat(
								"yyyy-MM-dd HH:mm:ss ");
						contenttime = sdf.format(dt);
						photo.setContentTime(contenttime);
					}
				}
				flag = photoDAO.insert(photo);
				if (flag) {
					msg = "恭喜,图片添加成功!";
				} else {
					msg = "对不起,图片插入失败!";
				}
			} catch (Exception e) {
				e.printStackTrace();
				msg = "图片插入失败!";
			}
			request.setAttribute("msg", msg);
			request.getRequestDispatcher("/admin/result.jsp").forward(request,
					response);
		}
	}

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

	public void init() throws ServletException {
	}

}

完整源码

觉得有用,记得一键三连哦!

  • 4
    点赞
  • 46
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
### 回答1: 基于servlet+jsp+mysql开发的JavaWeb学生成绩管理系统,可以实现对学生信息、课程信息和成绩信息的管理。系统的主要功能包括学生信息的添加修改、删除和查询,课程信息的添加修改、删除和查询,成绩信息的录入、修改、删除和查询等。同时,系统还可以生成各种报表,如学生信息报表、课程信息报表、成绩信息报表等,方便管理员进行数据分析和决策。系统的开发需要掌握JavaWeb开发技术、ServletJSP的使用、MySQL数据库的操作等知识。 ### 回答2: JavaWeb学生成绩管理系统是一项基于servletjspmysql开发的管理信息系统,旨在为教育管理部门和教师提供一个便利的平台,帮助他们轻松地管理和分析学生成绩和课程信息。 该系统涵盖了学生信息管理、课程信息管理、成绩管理、教师信息管理管理员信息管理五个模块。在学生信息管理模块,管理员可以添加修改及删除学生信息,同时可对学生信息进行查询和导出等操作;在课程信息管理模块,管理员可以添加修改及删除课程信息,同时可对课程信息进行查询和导出等操作。 在成绩管理模块,管理员可以将学生从课程中添加进去,对学生的成绩进行管理修改及删除等操作。同时,该模块内置了成绩分析和统计功能,使得教师可以使用统计图表看到平均分、最高分、最低成绩等信息,以更好地了解学生的学习情况。 在教师信息管理模块,管理员可以添加修改及删除教师信息,同时可对教师信息进行查询和导出等操作。教师可以使用该模块对自己授课的课程进行成绩管理并进行统计分析。 在管理员信息管理模块,管理员可以对自己的账号信息进行管理,包括修改密码添加、删除及修改管理员信息等操作。 总体来说,JavaWeb学生成绩管理系统通过servletjspmysql等技术的应用,实现了对学生成绩、课程等信息进行全方位管理,并且使得数据的统计、排序、查询等功能更加的便捷和高效,为教育管理和学习提供了极大的便利。 ### 回答3: 基于servlet jsp mysql开发javaweb学生成绩管理系统是一种非常实用的系统,可以帮助管理者和学生更好地进行成绩管理。通过该系统,管理者可以随时查看学生的成绩情况,对学生进行动态管理,帮助学生更好地提高成绩。同时,学生也可以随时了解自己在课程中的成绩和提升方向,方便自我调整和完善。 该系统采用了servlet jsp mysql技术进行开发,具有以下优点: 1. 通过servlet技术,可以实现后台数据传输和处理,确保系统的稳定性和安全性; 2. 通过jsp技术,可以实现动态网页的生成和展示,提供更好的用户体验;同时,jsp还可以方便地进行数据查询和修改操作; 3. 通过mysql作为数据库,可以实现数据的存储和管理,确保数据的完整性和可靠性;同时,mysql还具有较高的性能和扩展性,可以满足系统的快速增长。 在实现该系统时,需要进行以下步骤: 1. 分析需求,确定系统的功能和界面设计; 2. 设计数据库结构,确定数据表和字段; 3. 编写servletjsp代码,实现数据的查询、修改和展示功能; 4. 联调测试,确保系统的稳定性和可用性; 5. 部署上线,让用户可以随时使用系统。 总之,基于servlet jsp mysql技术开发javaweb学生成绩管理系统,可以有效提高学生的成绩和帮助管理者更好地管理学生成绩,是一种非常实用和有用的系统。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

anmu4200

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值