sx:tree 标签生成树状的文件列表

参照 Java Web 开发实战1200例写的一个将HDFS文件以树状形式展示的文件列表

因为是为了复制和移动的功能写的,故只显示文件夹

点击确定会在文本框中显示选择文件的路径

package com.suiyue;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

public class HdfsList {
	private FileSystem fileSystem;
	private FileStatus fileStatus;
	private String hdfsFileName;
	public String getHdfsFileName() {
		return hdfsFileName;
	}
	public void setHdfsFileName(String hdfsFileName) {
		this.hdfsFileName = hdfsFileName;
	}
	private List list = new ArrayList();
	private String hdfsPath;
	public String getHdfsPath() {
		return hdfsPath;
	}
	public void setHdfsPath(String hdfsPath) {
		this.hdfsPath = hdfsPath;
	}
	public FileSystem getFileSystem() {
		return fileSystem;
	}
	public void setFileSystem(FileSystem fileSystem) {
		this.fileSystem = fileSystem;
	}
	public FileStatus getFileStatus() {
		return fileStatus;
	}
	public void setFileStatus(FileStatus fileStatus) {
		this.fileStatus = fileStatus;
	}
	public List getList() {
		return list;
	}
	public void setList(List list) {
		this.list = list;
	}
	public  static String HdfsPath() {
		return "hdfs://localhost:9001/user";
	}
	
	public HdfsList(String hdfsPath){
		this.hdfsPath = hdfsPath;	
		Path path = new Path(hdfsPath);
		this.hdfsFileName = path.getName();
		Configuration conf = new Configuration();
		FileSystem fs;
		try {
			fs = FileSystem.get(conf);	
			FileStatus[] files = fs.listStatus(path);
			for(int i=0; i


<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"
import = "com.suiyue.HdfsList"
import = "org.apache.hadoop.fs.*"%>
<%@ taglib  uri="/struts-tags"  prefix="s"%>
<%@ taglib prefix="sx" uri="/struts-dojo-tags"%>  
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>



  
    
    
    My JSP 'index.jsp' starting page
	
	
	    
	
	
	
	
	
	
   
  
     文件列表:
   	<%
    	request.setAttribute("file", new HdfsList(HdfsList.HdfsPath()));
     %>   
     
     	
     	
     	
     	
  

你可能感兴趣的:(SSH)