栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

大数据接私活200元,做个简易的HDFS浏览器(一)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

大数据接私活200元,做个简易的HDFS浏览器(一)

大数据接私活200元,做个简易的HDFS浏览器(一) 需求

接到一个单子说是用制作一个简单的HDFS浏览器。

功能包括:基于HDFS的文件浏览、上传和下载。

需求分析

​ 用到的技术包括Java、HDFSAPI、tomcat的配置等

代码实现

项目架构:

Controller层代码:

@Controller
@RequestMapping("/hdfs")
public class hdfsController {
   
   
   
   private hdfsService hdfsService;   
   public hdfsService getHdfsService() {
      return hdfsService;
   }
    @Resource
   public void setHdfsService(hdfsService hdfsService) {
      this.hdfsService = hdfsService;
   }

   @RequestMapping("/delete")  
    public String toDelete(@RequestParam(value="path",required=false) String path)
       throws IOException{  
        hdfsService.delete(path);            
          return "success";       
}


    @RequestMapping(value="/ls",method=RequestMethod.GET)
       public ModelAndView home(@RequestParam(value="path",required=false) String path, HttpServletRequest request, HttpServletResponse response) 
          throws Exception {
          ModelAndView model = new ModelAndView();
           if (StringUtils.isEmpty(path)) {
               path = "/";
           } 
         List hdfsFiles =hdfsService.ls(path);
           model.addObject("file", hdfsFiles);
           model.setViewName("/ls");
           return model;
       }
    
    
    @RequestMapping("/download")  
       public String toDownload(@RequestParam(value="path",required=false) String path)
          throws IOException{  
          hdfsService.download(path);           
             return "success";       
   }
    
    
    @RequestMapping(value="/upload")
    public String upLoad(HttpServletRequest request, HttpServletResponse response) 
               throws IllegalStateException, IOException{
           //解析器解析request的上下文
           CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(request.getSession().getServletContext()); 
           //先判断request中是否包涵multipart类型的数据,
           if(multipartResolver.isMultipart(request)) {
               //再将request中的数据转化成multipart类型的数据
               MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
               Iterator iter = multiRequest.getFileNames();
               while(iter.hasNext()) {
                   MultipartFile file = multiRequest.getFile(iter.next());
                   if(file != null) {
                      String FileName = file.getOriginalFilename();
                      System.out.println(FileName);
                       CommonsMultipartFile cf= (CommonsMultipartFile)file; 
                       DiskFileItem fi = (DiskFileItem)cf.getFileItem(); 
                       File inputFile = fi.getStoreLocation();
                       hdfsService.createFile(inputFile, "hdfs://192.168.88.100:8020/upload/"+FileName);
                   }
               }
           }
           return "success";
       }

前端部分页面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
   pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page isELIgnored="false" %> 
<%String ref = request.getHeader("REFERER");%>  




HDFS文件管理器



     
文件名 文件大小 拥有者 权限 时间      操作
${file.fileName} ${file.fileSize} ${file.owner} ${file.permission} ${file.modificationTime} 删除    下载
效果演示

HDFS简易Web浏览器

HDFS简易Web浏览器_哔哩哔哩_bilibili

总结

比较轻松的需求,主要是之前做过类似的小项目直接拿来用即可。

如果想要接Java和大数据方面私活的,有赚零花钱想法的,可以点下方的小卡片与我联系或者在CSDN私信我。

我和我的团队能够提供什么?
1.优质的接单群,一单最低50。
2.持续终身的售后服务,有任何接单不懂的地方可以问我,提供1v1售后,接单有保障。
3.针对不怎么懂技术的小白,提供价值大几千的代码生成器,即使是小白也能轻松接私活。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/998454.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号