1

我正在使用 jquery 文件树来显示我的本地文件系统,但是我遇到了一些问题。嗯,我在我的项目中使用了maven+jersey+guice,并且我修改了版本jsp,我在我的controler中创建了一个类,代码如下:

@Path("/monurl")
@POST
@Produces({MediaType.TEXT_HTML})
public Response getGsp(@Context HttpServletRequest request) throws UnsupportedEncodingException
{


    StringBuffer buffer = new StringBuffer();

    String dir = request.getParameter("dir");

    if (dir == null) {
        return Response.ok("").build();
    }

    if (dir.charAt(dir.length()-1) == '\\') {
        dir = dir.substring(0, dir.length()-1) + "/";
    } else if (dir.charAt(dir.length()-1) != '/') {
        dir += "/";
    }

    dir = java.net.URLDecoder.decode(dir, "UTF-8"); 

    if (new File(dir).exists()) {
        String[] files = new File(dir).list(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return name.charAt(0) != '.';
            }
        });
        Arrays.sort(files, String.CASE_INSENSITIVE_ORDER);
        buffer.append("<ul class=\"jqueryFileTree\" style=\"display: none;\">");
        // All dirs
        for (String file : files) {
            if (new File(dir, file).isDirectory()) {
                buffer.append("<li class=\"directory collapsed\"><a href=\"#\" rel=\"" + dir + file + "/\">"
                    + file + "</a></li>");
            }
        }
        // All files
        for (String file : files) {
            if (!new File(dir, file).isDirectory()) {
                int dotIndex = file.lastIndexOf('.');
                String ext = dotIndex > 0 ? file.substring(dotIndex + 1) : "";
                buffer.append("<li class=\"file ext_" + ext + "\"><a href=\"#\" rel=\"" + dir + file + "\">"
                    + file + "</a></li>");
                }
        }
        buffer.append("</ul>");
    }

    log.debug("Response content {}", buffer.toString());
    return Response.ok(buffer.toString()).build();  
}

对于代码 javascript:

    $(document).ready( function() {

            $('#JQueryFTD_Demo').fileTree({
              root: '/home/y.zhang/kernely/kernely/work/',
              script: '/ged/monurl',
              expandSpeed: 1000,
              collapseSpeed: 1000,
              multiFolder: true
            }, function(file) {
                alert(file);
            });         
        });
    </script>

但是我总是遇到遍历我的文件夹的问题,并且从萤火虫中,我观察到我的服务器返回 200 OK 128ms。那么,我的代码有问题吗?提前致谢。

4

0 回答 0