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

网友投稿 1294 2022-09-28

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

大数据接私活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="page isELIgnored="false" %> <%String ref = request.getHeader("REFERER");%> HDFS文件管理器

文件名 文件大小 拥有者 权限 时间      操作
${file.fileName} ${file.fileSize} ${file.owner} ${file.permission} ${file.modificationTime} 删除    -

效果演示

HDFS简易Web浏览器

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

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:银行如何实现客群精准营销?小程序技术打通金融服务与社交平台
下一篇:工作总结之服务器时间不同步导致平台验证失败及Linux系统时间同步方法
相关文章

 发表评论

暂时没有评论,来抢沙发吧~