发布时间:2023-10-03 18:00
接到一个单子说是用制作一个简单的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<hdfsBean> 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<String> 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");%>
DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>HDFS文件管理器title>
head>
<body>
<table>
<tr>
<td>文件名td>
<td>文件大小 td>
<td>拥有者 td>
<td>权限 td>
<td>时间 td>
<td> 操作td>
tr>
<c:forEach var="file" items="${file}">
<tr>
<td><a href="${pageContext.request.contextPath}/hdfs/ls.do?path=${file.fileName}" style="color:#666666;text-decoration:none;">
${file.fileName}a>td>
<td> ${file.fileSize}td>
<td> ${file.owner}td>
<td> ${file.permission}td>
<td> ${file.modificationTime}td>
<td><a href="${pageContext.request.contextPath}/hdfs/delete.do?path=${file.fileName}" style="color:#666666;text-decoration:none;"
class="button border-dot button-little" onclick="return confirm('确认删除?')" >
删除 a>
<a href="${pageContext.request.contextPath}/hdfs/download.do?path=${file.fileName}" style="color:#666666;text-decoration:none;">
下载a>td>
tr>
c:forEach>
<input type="button" value="返回" onclick="javascript:window.location='<%=ref%>'" >
table>
body>
html>
HDFS简易Web浏览器
HDFS简易Web浏览器_哔哩哔哩_bilibili
比较轻松的需求,主要是之前做过类似的小项目直接拿来用即可。
如果想要接Java和大数据方面私活的,有赚零花钱想法的,可以点下方的小卡片与我联系。
Angular InjectionToken APP_INITIALIZER multi 标志位不同值的情况讨论
python中__name__属性的取值_python中__name__是什么意思
基于 Kubernetes 和 Spring Cloud 的微服务化实践
在线下单系统php源码,PIMS在线订单管理系统v4.2.9
黑马程序员3天带你玩转Python深度学习TensorFlow框架学习笔记
Windows VSCode 安装C++ 一定可以的 详细版
网络聊天java源码_WebSocket,JAVA,在线聊天程序DEMO(附源码下载)
Silane-PEG-NHS,SIL-PEG-NHS,可以用来修饰蛋白质、多肽以及其他活性基团,NHS-PEG-Silane