基于javaweb+mysql的jsp+servlet相册管理系统文件图片管理(java+jsp+servlet+mysql)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的JSP+Servlet相册管理系统文件图片管理(java+jsp+servlet+mysql)
管理员:
admin 123456
用户:
user 123456
request.setAttribute("dbUserId", dbUserId);
}
String name = request.getParameter("name");
if (name != null && name != "") {
photoAlbum.setName(name);
request.setAttribute("name", name);
}
String isPublic = request.getParameter("isPublic");
if (isPublic != null && isPublic != "") {
photoAlbum.setIsPublic(isPublic);
request.setAttribute("isPublic", isPublic);
}
String password = request.getParameter("password");
if (password != null && password != "") {
photoAlbum.setPassword(password);
request.setAttribute("password", password);
}
String downOrRead = request.getParameter("downOrRead");
if (downOrRead != null && downOrRead != "") {
photoAlbum.setDownOrRead(downOrRead);
request.setAttribute("downOrRead", downOrRead);
}
//判断提示信息
Object msg = request.getSession().getAttribute("msg");
if (msg != null) {
request.setAttribute("msg", msg.toString());
request.getSession().removeAttribute("msg");
}
page = photoAlbumService.page(photoAlbum, page);
request.setAttribute("page", page);
request.getRequestDispatcher("/views/system/photoAlbumList.jsp").forward(request, response);
}
//列表查询
private void mainindex(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.err.println("---开始查询---");
PhotoAlbum photoAlbum = new PhotoAlbum();
//分页有关
Page<PhotoAlbum> page = new Page<PhotoAlbum>();
//设置查询页
String pageNoStr = request.getParameter("pageNo");
if (pageNoStr != null && pageNoStr != "") {
page.setPageNo(Integer.parseInt(pageNoStr));
}
//设置查询条件
String dbUserId = request.getParameter("dbUserId");
if (dbUserId != null && dbUserId != "") {
photoAlbum.setDbUserId(dbUserId);
request.setAttribute("dbUserId", dbUserId);
}
String name = request.getParameter("name");
if ("id".endsWith(name)) {
if (str!=null && str!="") {
photoAlbum.setId(str);
}
}
if ("mainPicPath".endsWith(name)) {
photoAlbum.setMainPicPath(str);
}
if ("dbUserId".endsWith(name)) {
photoAlbum.setDbUserId(str);
}
if ("name".endsWith(name)) {
photoAlbum.setName(str);
}
if ("createTime".endsWith(name)) {
photoAlbum.setCreateTime(str);
}
if ("isPublic".endsWith(name)) {
photoAlbum.setIsPublic(str);
}
if ("passHint".endsWith(name)) {
photoAlbum.setPassHint(str);
}
if ("password".endsWith(name)) {
photoAlbum.setPassword(str);
}
//获取上传文件的路径
String savePath = PropertiesUtil.getValue("fileUpload");
File file = new File(savePath+"/");
if (!file.exists() && !file.isDirectory()) {
System.out.println(savePath+"目录不存在,需要创建");
//创建目录
file.mkdirs();
}
//消息提示
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中封装的是普通输入项的数据
String str = "";
String name = item.getFieldName();
if(item.isFormField()){
str = item.getString("UTF-8");
}else{//如果fileitem中封装的是上传文件
//得到上传的文件名称,
String filename = item.getName();
if(filename==null || filename.trim().equals("")){
continue;
}
//注意:不同的浏览器提交的文件名是不一样的,有些浏览器提交上来的文件名是带有路径的,如: c:\a\b\1.txt,而有些只是单纯的文件名,如:1.txt
//处理获取到的上传文件的文件名的路径部分,只保留文件名部分
// filename = filename.substring(filename.lastIndexOf("\\")+1);
filename = IdGenUtil.getUUID()+"."+ filename.substring(filename.lastIndexOf(".")+1);
System.out.println(filename);
//获取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){
//得到上传的文件名称,
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 = "文件上传成功!";
// user.setPic("\\upload" + "\\" + filename);
}
}
if (user.getId() != null && !"".equals(user.getId())) {
userService.update(user);
} else {
user.setRole("2");//添加的用户默认为普通管理员
user.setPassword(MD5.Encrypt("123456"));
userService.add(user);
}
response.sendRedirect(contextPath + "/user?method=list");
} catch (Exception e) {
msg = "文件上传失败!";
e.printStackTrace();
request.setAttribute("msg", msg);
request.getRequestDispatcher("/views/system/userForm.jsp").forward(request, response);
}
}
//删除
private void delete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String id = request.getParameter("id");
userService.delete(id);
user.setContent(content);
user.setFileSize(Double.parseDouble(fileSize));
userService.update(user);
request.setAttribute("user", user);
request.setAttribute("msg", "个人信息修改成功!!");
request.getSession().setAttribute("login", user);
request.getRequestDispatcher("/views/system/userInfo.jsp").forward(request, response);
}
//列表查询
private void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.err.println("---开始查询---");
User user = new User();
//分页有关
Page<User> page = new Page<User>();
//设置查询页
String pageNoStr = request.getParameter("pageNo");
if (pageNoStr != null && pageNoStr != "") {
page.setPageNo(Integer.parseInt(pageNoStr));
}
//设置查询条件
String username = request.getParameter("username");
if (username != null && username != "") {
user.setUsername(username);
request.setAttribute("username", username);
}
String name = request.getParameter("name");
if (name != null && name != "") {
user.setName(name);
request.setAttribute("name", name);
}
String sex = request.getParameter("sex");
if (sex != null && sex != "") {
user.setSex(sex);
request.setAttribute("sex", sex);
}
String parameter = request.getParameter("msg");
if (parameter != null && parameter != "") {
request.setAttribute("msg", parameter);
}
page = userService.page(user, page);
request.setAttribute("page", page);
request.getRequestDispatcher("/views/system/userList.jsp").forward(request, response);
//分页有关
Page<PhotoAlbum> page = new Page<PhotoAlbum>();
//设置查询页
String pageNoStr = request.getParameter("pageNo");
if (pageNoStr != null && pageNoStr != "") {
page.setPageNo(Integer.parseInt(pageNoStr));
}
//设置查询条件
photoAlbum.setDbUserId(UserUtil.currentUser(request).getId());
String name = request.getParameter("name");
if (name != null && name != "") {
photoAlbum.setName(name);
request.setAttribute("name", name);
}
String isPublic = request.getParameter("isPublic");
if (isPublic != null && isPublic != "") {
photoAlbum.setIsPublic(isPublic);
request.setAttribute("isPublic", isPublic);
}
String password = request.getParameter("password");
if (password != null && password != "") {
photoAlbum.setPassword(password);
request.setAttribute("password", password);
}
String downOrRead = request.getParameter("downOrRead");
if (downOrRead != null && downOrRead != "") {
photoAlbum.setDownOrRead(downOrRead);
request.setAttribute("downOrRead", downOrRead);
}
//判断提示信息
Object msg = request.getSession().getAttribute("msg");
if (msg != null) {
request.setAttribute("msg", msg.toString());
request.getSession().removeAttribute("msg");
}
page = photoAlbumService.page(photoAlbum, page);
request.setAttribute("page", page);
request.getRequestDispatcher("/views/system/photoAlbumMine.jsp").forward(request, response);
}
String password = request.getParameter("password");
if (password != null && password != "") {
photoAlbum.setPassword(password);
request.setAttribute("password", password);
}
String downOrRead = request.getParameter("downOrRead");
if (downOrRead != null && downOrRead != "") {
photoAlbum.setDownOrRead(downOrRead);
request.setAttribute("downOrRead", downOrRead);
}
//判断提示信息
Object msg = request.getSession().getAttribute("msg");
if (msg != null) {
request.setAttribute("msg", msg.toString());
request.getSession().removeAttribute("msg");
}
page = photoAlbumService.page(photoAlbum, page);
request.setAttribute("page", page);
request.getRequestDispatcher("/views/system/photoAlbumList.jsp").forward(request, response);
}
//列表查询
private void mainindex(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.err.println("---开始查询---");
PhotoAlbum photoAlbum = new PhotoAlbum();
//分页有关
Page<PhotoAlbum> page = new Page<PhotoAlbum>();
//设置查询页
String pageNoStr = request.getParameter("pageNo");
if (pageNoStr != null && pageNoStr != "") {
page.setPageNo(Integer.parseInt(pageNoStr));
}
//设置查询条件
String dbUserId = request.getParameter("dbUserId");
if (dbUserId != null && dbUserId != "") {
photoAlbum.setDbUserId(dbUserId);
request.setAttribute("dbUserId", dbUserId);
}
System.out.println(savePath + "目录不存在,需要创建");
//创建目录
file.mkdirs();
}
//消息提示
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中封装的是普通输入项的数据
String str = "";
String name = item.getFieldName();
if (item.isFormField()) {
str = item.getString("UTF-8");
} else {//如果fileitem中封装的是上传文件
//得到上传的文件名称,
String filename = item.getName();
if (filename == null || filename.trim().equals("")) {
continue;
}
//注意:不同的浏览器提交的文件名是不一样的,有些浏览器提交上来的文件名是带有路径的,如: c:\a\b\1.txt,而有些只是单纯的文件名,如:1.txt
//处理获取到的上传文件的文件名的路径部分,只保留文件名部分
// filename = filename.substring(filename.lastIndexOf("\\")+1);
filename = IdGenUtil.getUUID() + "." + filename.substring(filename.lastIndexOf(".") + 1);
System.out.println(filename);
//获取item中的上传文件的输入流
InputStream in = item.getInputStream();
//创建一个文件输出流
private void userInfo(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.getRequestDispatcher("/views/system/userInfo.jsp").forward(request, response);
}
private void fixPass(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String id = request.getParameter("id");
String password = request.getParameter("password");
User byId = userService.getById(id);
byId.setPassword(MD5.Encrypt(password));
userService.update(byId);
request.setAttribute("msg", "密码修改成功");
request.getSession().setAttribute("login", byId);
request.getRequestDispatcher("/views/system/userPassFix.jsp").forward(request, response);
}
/**
* 跳转到修改密码界面
*
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
private void userPassFix(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.getRequestDispatcher("/views/system/userPassFix.jsp").forward(request, response);
}
private void checkPass(HttpServletRequest request, HttpServletResponse response) throws IOException {
User currentUser = UserUtil.currentUser(request);
if (currentUser != null) {
String oldpassword = request.getParameter("oldpassword");
if (currentUser.getPassword().equals(MD5.Encrypt(oldpassword))) {
response.getWriter().write("true");
} else {
response.getWriter().write("false");
}
} else {
response.getWriter().write("false");
}
}
private void checkUserName(HttpServletRequest request, HttpServletResponse response) throws IOException {
String username = request.getParameter("username");
User user = new User();
user.setUsername(username);
List<User> findAll = userService.findAll(user);
if (findAll != null && findAll.size() > 0) {
request.getRequestDispatcher("/views/system/userInfo.jsp").forward(request, response);
}
//列表查询
private void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.err.println("---开始查询---");
User user = new User();
//分页有关
Page<User> page = new Page<User>();
//设置查询页
String pageNoStr = request.getParameter("pageNo");
if (pageNoStr != null && pageNoStr != "") {
page.setPageNo(Integer.parseInt(pageNoStr));
}
//设置查询条件
String username = request.getParameter("username");
if (username != null && username != "") {
user.setUsername(username);
request.setAttribute("username", username);
}
String name = request.getParameter("name");
if (name != null && name != "") {
user.setName(name);
request.setAttribute("name", name);
}
String sex = request.getParameter("sex");
if (sex != null && sex != "") {
user.setSex(sex);
request.setAttribute("sex", sex);
}
String parameter = request.getParameter("msg");
if (parameter != null && parameter != "") {
request.setAttribute("msg", parameter);
}
page = userService.page(user, page);
request.setAttribute("page", page);
request.getRequestDispatcher("/views/system/userList.jsp").forward(request, response);
}
//form跳转页面
private void form(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String id = request.getParameter("id");
//判断提示信息
Object msg = request.getSession().getAttribute("msg");
if (msg != null) {
request.setAttribute("msg", msg.toString());
request.getSession().removeAttribute("msg");
}
page.setPageSize(200);
page = pictureInfoService.page(pictureInfo, page);
request.setAttribute("page", page);
String currentNum = request.getParameter("currentNum");
request.setAttribute("currentNum", Integer.parseInt(currentNum));
request.getRequestDispatcher("/views/system/pictureInfoShow.jsp").forward(request, response);
}
}
@WebServlet("/user")
public class UserController extends HttpServlet {
userPassFix(request, response);
} else if ("checkPass".equals(method)) {
checkPass(request, response);
} else if ("fixPass".equals(method)) {
fixPass(request, response);
} else if ("userInfo".equals(method)) {
userInfo(request, response);
} else if ("pay".equals(method)) {
pay(request, response);
} else if ("savePay".equals(method)) {
savePay(request, response);
}
}
private void userInfo(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.getRequestDispatcher("/views/system/userInfo.jsp").forward(request, response);
}
private void fixPass(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String id = request.getParameter("id");
String password = request.getParameter("password");
User byId = userService.getById(id);
byId.setPassword(MD5.Encrypt(password));
userService.update(byId);
request.setAttribute("msg", "密码修改成功");
request.getSession().setAttribute("login", byId);
request.getRequestDispatcher("/views/system/userPassFix.jsp").forward(request, response);
}
/**
* 跳转到修改密码界面
*
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
private void userPassFix(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//使用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中封装的是普通输入项的数据
String str = "";
String name = item.getFieldName();
if (item.isFormField()) {
str = item.getString("UTF-8");
} else {//如果fileitem中封装的是上传文件
//得到上传的文件名称,
String filename = item.getName();
if (filename == null || filename.trim().equals("")) {
continue;
}
//注意:不同的浏览器提交的文件名是不一样的,有些浏览器提交上来的文件名是带有路径的,如: c:\a\b\1.txt,而有些只是单纯的文件名,如:1.txt
//处理获取到的上传文件的文件名的路径部分,只保留文件名部分
// filename = filename.substring(filename.lastIndexOf("\\")+1);
filename = IdGenUtil.getUUID() + "." + filename.substring(filename.lastIndexOf(".") + 1);
System.out.println(filename);
//获取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里面还有数据
double filesize = 0.0;
while ((len = in.read(buffer)) > 0) {
//使用FileOutputStream输出流将缓冲区的数据写入到指定的目录(savePath + "\\" + filename)当中
filesize = filesize + len;
out.write(buffer, 0, len);
}
pictureInfo.setFileSize((double) Math.round(filesize / 1024));
//关闭输入流
String password = request.getParameter("password");
String name = request.getParameter("name");
String sex = request.getParameter("sex");
String phone = request.getParameter("phone");
String content = request.getParameter("content");
String fileSize = request.getParameter("fileSize");
User user = new User();
user.setId(id);
user.setRole(role);
user.setUsername(username);
user.setPassword(password);
user.setName(name);
user.setSex(sex);
user.setPhone(phone);
user.setContent(content);
user.setFileSize(Double.parseDouble(fileSize));
userService.update(user);
request.setAttribute("user", user);
request.setAttribute("msg", "个人信息修改成功!!");
request.getSession().setAttribute("login", user);
request.getRequestDispatcher("/views/system/userInfo.jsp").forward(request, response);
}
//列表查询
private void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.err.println("---开始查询---");
User user = new User();
//分页有关
Page<User> page = new Page<User>();
//设置查询页
String pageNoStr = request.getParameter("pageNo");
if (pageNoStr != null && pageNoStr != "") {
page.setPageNo(Integer.parseInt(pageNoStr));
}
//设置查询条件
String username = request.getParameter("username");
if (username != null && username != "") {
user.setUsername(username);
request.setAttribute("username", username);
}
String name = request.getParameter("name");
if (name != null && name != "") {
user.setName(name);
request.setAttribute("name", name);
}
String sex = request.getParameter("sex");
if (sex != null && sex != "") {
user.setSex(sex);
request.setAttribute("sex", sex);
}
String parameter = request.getParameter("msg");
String dbUserId = request.getParameter("dbUserId");
if (dbUserId != null && dbUserId != "") {
photoAlbum.setDbUserId(dbUserId);
request.setAttribute("dbUserId", dbUserId);
}
String name = request.getParameter("name");
if (name != null && name != "") {
photoAlbum.setName(name);
request.setAttribute("name", name);
}
String isPublic = request.getParameter("isPublic");
if (isPublic != null && isPublic != "") {
photoAlbum.setIsPublic(isPublic);
request.setAttribute("isPublic", isPublic);
}
String password = request.getParameter("password");
if (password != null && password != "") {
photoAlbum.setPassword(password);
request.setAttribute("password", password);
}
String downOrRead = request.getParameter("downOrRead");
if (downOrRead != null && downOrRead != "") {
photoAlbum.setDownOrRead(downOrRead);
request.setAttribute("downOrRead", downOrRead);
}
//判断提示信息
Object msg = request.getSession().getAttribute("msg");
if (msg != null) {
request.setAttribute("msg", msg.toString());
request.getSession().removeAttribute("msg");
}
page = photoAlbumService.page(photoAlbum, page);
request.setAttribute("page", page);
request.getRequestDispatcher("/views/system/photoAlbumList.jsp").forward(request, response);
}
//列表查询
private void mainindex(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.err.println("---开始查询---");
PhotoAlbum photoAlbum = new PhotoAlbum();
//分页有关
Page<PhotoAlbum> page = new Page<PhotoAlbum>();
page.setPageSize(200);
page = pictureInfoService.page(pictureInfo, page);
request.setAttribute("page", page);
request.getRequestDispatcher("/views/system/pictureInfoDetail.jsp").forward(request, response);
}
//相册详情
private void turnBack(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("---相册详情查询---");
PictureInfo pictureInfo = new PictureInfo();
//分页有关
Page<PictureInfo> page = new Page<PictureInfo>();
//设置查询页
String pageNoStr = request.getParameter("pageNo");
if (pageNoStr != null && pageNoStr != "") {
page.setPageNo(Integer.parseInt(pageNoStr));
}
//设置查询条件
String photoAlbumId = request.getParameter("photoAlbumId");
if (photoAlbumId != null && photoAlbumId != "") {
pictureInfo.setPhotoAlbumId(photoAlbumId);
request.setAttribute("photoAlbumId", photoAlbumId);
}
pictureInfo.setPicStatue("1");//
String backTimeLimit = request.getParameter("backTimeLimit");
if (backTimeLimit != null && backTimeLimit != "") {
request.setAttribute("backTimeLimit", backTimeLimit);
}
//判断提示信息
Object msg = request.getSession().getAttribute("msg");
if (msg != null) {
request.setAttribute("msg", msg.toString());
request.getSession().removeAttribute("msg");
}
page.setPageSize(200);
page = pictureInfoService.page(pictureInfo, page);
request.setAttribute("page", page);
request.getRequestDispatcher("/views/system/pictureInfoBack.jsp").forward(request, response);
}
//form跳转页面
private void form(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String id = request.getParameter("id");
PictureInfo pictureInfo = new PictureInfo();
if (id != null && id != "") {
pictureInfo = pictureInfoService.getById(id);
} else {
request.getRequestDispatcher("/views/system/userPassFix.jsp").forward(request, response);
}
/**
* 跳转到修改密码界面
*
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
private void userPassFix(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.getRequestDispatcher("/views/system/userPassFix.jsp").forward(request, response);
}
private void checkPass(HttpServletRequest request, HttpServletResponse response) throws IOException {
User currentUser = UserUtil.currentUser(request);
if (currentUser != null) {
String oldpassword = request.getParameter("oldpassword");
if (currentUser.getPassword().equals(MD5.Encrypt(oldpassword))) {
response.getWriter().write("true");
} else {
response.getWriter().write("false");
}
} else {
response.getWriter().write("false");
}
}
private void checkUserName(HttpServletRequest request, HttpServletResponse response) throws IOException {
String username = request.getParameter("username");
User user = new User();
user.setUsername(username);
List<User> findAll = userService.findAll(user);
if (findAll != null && findAll.size() > 0) {
//用户名存在
System.out.println("用户名存在了");
response.getWriter().write("false");
} else {
System.out.println("用户名不存在");
response.getWriter().write("true");
}
}
private void logout(HttpServletRequest request, HttpServletResponse response) throws IOException {
request.getSession().invalidate();
@WebServlet("/pictureInfo")
public class PictureInfoController extends HttpServlet {
private static final long serialVersionUID = 1L;
private String contextPath = "";
PictureInfoDao pictureInfoDao = new PictureInfoDao();
PictureInfoService pictureInfoService = new PictureInfoServiceImpl();
UserService userService = new UserServiceImpl();
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
contextPath = request.getServletContext().getContextPath();
String method = request.getParameter("method");
if ("save".equals(method)) {
save(request, response);
} else if ("delete".equals(method)) {
delete(request, response);
} else if ("list".equals(method)) {
list(request, response);
} else if ("form".equals(method)) {
form(request, response);
} else if ("detail".equals(method)) {
detail(request, response);
} else if ("picShow".equals(method)) {
picShow(request, response);
} else if ("turnBack".equals(method)) {
turnBack(request, response);
} else if ("del".equals(method)) {
del(request, response);
} else if ("back".equals(method)) {
back(request, response);