基于hdfs+javaweb的简易网盘--(4)具体功能的实现

本文档详细介绍了如何结合HDFS、jsp和servlet创建一个简易网盘,包括管理界面、文件删除、上传下载、创建文件夹、移动功能及进入子文件夹等操作。前端通过传递路径,后端利用HdfsDao对HDFS进行操作。代码中存在安全性问题,适合初学者参考学习。
摘要由CSDN通过智能技术生成

1.管理界面

  • 由于代码嵌入了比较多的java代码,看起来比较凌乱,不理解的请在下方留言吧
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="org.apache.hadoop.fs.FileStatus"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>欢迎使用-bobo网盘</title>
<!-- 新 Bootstrap4 核心 CSS 文件 -->
<link rel="stylesheet"
	href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
<link rel="icon"
	href="https://cdn.jsdelivr.net/gh/wangyang-o/imgcdn/img/20200512002714.png"
	type="image/x-icon">
<link
	href="https://cdn.bootcdn.net/ajax/libs/font-awesome/4.7.0/css/font-awesome.css"
	rel="stylesheet">
</head>
<body class="container">
	<%
		FileStatus[] list = (FileStatus[]) request.getAttribute("documentList");
	String name = (String) session.getAttribute("username");
	String thisPath;
	if (request.getAttribute("thisPath") == null) {
		thisPath = name;
	} else {
		thisPath = (String) request.getAttribute("thisPath");
	}
	String result;//用户当前目录
	if (list.length != 0) {
		/*不知道怎么获取当前目录的路径,所以找到他一个子目录的父目录,前面一串路径都是一样的
		比如hdfs://localhost:9000/user/wangyang/user/wy/dir1/
		你点击了dir2,你就只需要得到hdfs://localhost:9000/user/wangyang/user/wy/+你点击的路径dir2
		*/
		result = list[0].getPath().getParent().toString().substring(40);
	} else {
		result = "";
	}
	%>
	<nav class="navbar navbar-expand-lg navbar-light bg-light mt-5">
		<a class="navbar-brand" href="#">bobo<i
			class="fa fa-modx fa-spin m-1"></i>网盘
		</a>
		<button class="navbar-toggler" type="button" data-toggle="collapse"
			data-target="#navbarSupportedContent"
			aria-controls="navbarSupportedContent" aria-expanded="false"
			aria-label="Toggle navigation">
			<span class="navbar-toggler-icon"></span>
		</button>

		<a class="nav-link col-3">当前路径:<%=thisPath%></a>
		<form id="frm" class="form-inline my-2 my-lg-0"
			action="MkdirServlet?thisPath=<%=thisPath%>" method="post">
			<input class="form-control mr-sm-2 col-5" type="text"
				placeholder="输入文件夹名称" name="mkdir">
			<button class="btn btn-outline-success my-2 my-sm-0" type="submit">创建</button>
		</form>
		<form action="UploadServlet?thisPath=<%=thisPath%>" method="post"
			enctype="multipart/form-data">
			<div class="row">

				<div class="col-9">
					<input type="file" class="filestyle" data-badgeName="badge-danger"
						data-badge="true" data-placeholder="未选择" data-text="上传文件"
						name="myfile">
				</div>
				<div class="col-3 ml-0 pl-0">
					<button class="btn btn-secondary my-2 my-sm-0" type="submit">
						<i class="fa fa-upload" aria-hidden="true"></i>
					</button>
				</div>
			</div>
		</form>



	</nav>
	<table class="table table-hover " style="text-align: center">
		<thead class="thead-dark">
			<tr>
				<th scope="col">序号</th>
				<th scope="col">文件名</th>
				<th scope="col">属性</th>
				<th scope="col">大小</th>
				<th scope="col">可执行操作</th>
			</tr>
		</thead>
		<tbody>
			<%
				if (list != null) {

				for (int i = 0; i < list.length; i++) {
			%>
			<tr>
				<%
					out.print("<th scope='row'>" + (i + 1) + "</th>");
				if (list[i].isDir())//DocumentServlet
				{
					out.print("<td><strong>" + list[i].getPath().getName() + "</strong></td>");
				} else {
					out.print("<td>" + list[i].getPath().getName() + "</td>");
				}
				%>
				<td><%=(list[i].isDir() ? "<i class='fa fa-folder-open mr-1' aria-hidden='true'></i>目录"
		: "<i class='fa fa-file-text-o mr-1' aria-hidden='true'></i>文件")%></td>
				<td><%=(list[i].getLen())%></td>
				<td>
					<%
					String cut=(String)request.getAttribute("cut");
					if (list[i].isDir())//DocumentServlet
					{
						out.print("<a role='button' class='btn btn-outline-success' href='ShowChildDirServlet?filePath=" + result + "/"
						+ list[i].getPath().getName() + "&cut=" + cut + "'>
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值