• 大小: 3.06MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-09-10
  • 语言: 其他
  • 标签: 个人相册  云平台  

资源简介

借用第三方平台实现个人相册

资源截图

代码片段和文件信息

package action;

import java.io.IOException;
import java.util.Date;
import java.util.UUID;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;

import domain.Image;
import domain.User;
import service.ImageService;



/**
 * 图片控制器
 * @author www.shiyanlou.com
 *
 */

@MultipartConfig

public class ImageAction extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#doGet(HttpServletRequest request HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request HttpServletResponse response) throws ServletException IOException {
       doPost(request response);
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request HttpServletResponse response) throws ServletException IOException {
      request.setCharacterEncoding(“utf-8“);
         response.setCharacterEncoding(“utf-8“);
         response.setContentType(“text/html;charset=utf-8“);
         Integer type = Integer.valueOf(request.getParameter(“type“));
         ImageService imageService = new ImageService();

         if (type == 1) {    //上传图片
             String imageName = request.getParameter(“image_name“);
             System.out.println(imageName);
        
             Part image = request.getPart(“image“);
             if (image==null) {
  System.out.println(“image null“);
  }
             Image img = new Image();
             img.setDate(new Date());
             img.setName(imageName);
             img.setUser((User) request.getSession().getAttribute(“user“));
             
             img.setUrl(img.getUser().getUsername() + “/“ + UUID.randomUUID());
             imageService.addImage(img image.getInputStream());
             request.getSession().setAttribute(“imageList“ imageService.getByUserId(img.getUser().getId()));
             response.sendRedirect(request.getContextPath() + “/home.jsp“);
         } else if (type == 2) {    //删除图片
             String ids = request.getParameter(“ids“);
             String urls = request.getParameter(“urls“);
             imageService.delByIdsAndUrls(ids urls);
             request.getSession().setAttribute(“imageList“ imageService.getByUserId(((User) request.getSession().getAttribute(“user“)).getId()));
         }
    }

}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2016-10-25 16:15  photo\
     文件         275  2016-10-25 16:37  photo.sql
     文件         841  2016-10-23 15:26  photo\.classpath
     文件        1038  2016-10-23 15:26  photo\.project
     目录           0  2016-10-25 16:15  photo\.settings\
     文件         567  2016-10-23 15:26  photo\.settings\.jsdtscope
     文件         364  2016-10-23 15:26  photo\.settings\org.eclipse.jdt.core.prefs
     文件         467  2016-10-23 15:26  photo\.settings\org.eclipse.wst.common.component
     文件         345  2016-10-23 15:26  photo\.settings\org.eclipse.wst.common.project.facet.core.xml
     文件          49  2016-10-23 15:26  photo\.settings\org.eclipse.wst.jsdt.ui.superType.container
     文件           6  2016-10-23 15:26  photo\.settings\org.eclipse.wst.jsdt.ui.superType.name
     目录           0  2016-10-25 16:15  photo\build\
     目录           0  2016-10-25 16:15  photo\build\classes\
     目录           0  2016-10-25 16:15  photo\build\classes\action\
     文件        3487  2016-10-25 15:44  photo\build\classes\action\ImageAction.class
     文件        3293  2016-10-25 15:44  photo\build\classes\action\UserAction.class
     目录           0  2016-10-25 16:15  photo\build\classes\domain\
     文件        1383  2016-10-25 15:44  photo\build\classes\domain\Image.class
     文件        1902  2016-10-25 15:44  photo\build\classes\domain\User.class
     目录           0  2016-10-25 16:15  photo\build\classes\service\
     文件        3355  2016-10-25 15:44  photo\build\classes\service\ImageService.class
     文件        1669  2016-10-25 15:44  photo\build\classes\service\UserService.class
     目录           0  2016-10-25 16:15  photo\build\classes\util\
     文件        3628  2016-10-25 15:44  photo\build\classes\util\DBUtils.class
     文件        1815  2016-10-25 15:44  photo\build\classes\util\FileUtils.class
     目录           0  2016-10-25 16:15  photo\src\
     目录           0  2016-10-25 16:15  photo\src\action\
     文件        2647  2016-10-24 19:48  photo\src\action\ImageAction.java
     文件        3558  2016-10-24 19:48  photo\src\action\UserAction.java
     目录           0  2016-10-25 16:15  photo\src\domain\
     文件        1038  2016-10-24 19:47  photo\src\domain\Image.java
............此处省略47个文件信息

评论

共有 条评论