hadoop实现web上传、下载、更新、删除和文件追加
Hadoop是一个能够对大量数据进行分布式处理的软件框架。Hadoop 是可靠的,因为它假设计算元素和存储会失败,因此它维护多个工作数据副本,确保能够针对失败的节点重新分布处理。Hadoop实现了一个分布式文件系统(Hadoop Distributed File System),简称HDFS。HDFS有着高容错性的特点,并且设计用来部署在低廉的(low-cost)硬件上上传:
/**
*
* 上传控制类,上传页面跳转到这里
*
* @author科帮网
* @version[版本号, 2012-08-02]
* @see[相关类/方法]
* @sinceversion 1.0
*/
public class UploadHDFSServlet extends HttpServlet {
/** *
* * 该方法负责上传控制处理页面 *
* @param request 客户端到服务器的请求消息
* @param response 服务器返回给页面的消息
* @throws ServletException
* @throws IOException
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if(!isMultipart){
}else{
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
try {
List items = upload.parseRequest(request);
Iterator iter = items.iterator();
while(iter.hasNext()){
FileItem item = (FileItem)iter.next();
if(item.isFormField()){
String name = item.getFieldName();
System.out.println(name);
}else{
//表单名字
String fileName = item.getName();
InputStream uploadedStream = item.getInputStream();
HDFSOperation hdfsOperation = new HDFSOperation();
String hdfsPath = dfs.HDFSConfig.getHDFSPath() + fileName;
boolean flag = hdfsOperation.upLoad(uploadedStream, hdfsPath);
if(flag){
response.sendRedirect("success.jsp");
}else{
response.sendRedirect("failure.jsp");
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}配置:
<configuration>
<property>
<name>fs.default.name </name>
<value>hdfs://10.6.12.101:8888</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/home/hadoopuser/tmp</value>
</property>
</configuration>源码下载地址:点击下载
如果可以做一个样板出来就更好了~:lol 很不错哟,谢谢楼主,受教了。 这个项目太棒勒!下下来学习下! 不错不错不错,学习一下
页:
[1]