Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用spring和jsp在列表中显示上传的文档_Javascript_Spring_Jsp - Fatal编程技术网

Javascript 如何使用spring和jsp在列表中显示上传的文档

Javascript 如何使用spring和jsp在列表中显示上传的文档,javascript,spring,jsp,Javascript,Spring,Jsp,我已将文档上载到服务器文件夹,我想显示我已上载的所有文档。File folder=新文件(“path/to/your/upload/files/directory”); @RequestMapping(value = "/uploadFile", method = RequestMethod.POST) public @ResponseBody String uploadFileHandler(@RequestParam("file") MultipartFile file) { if

我已将文档上载到服务器文件夹,我想显示我已上载的所有文档。

File folder=新文件(“path/to/your/upload/files/directory”);
@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
public @ResponseBody String uploadFileHandler(@RequestParam("file") MultipartFile file) {

    if (!file.isEmpty()) {
        String name=file.getOriginalFilename();
        try {
            byte[] bytes = file.getBytes();

            // Creating the directory to store file
            String rootPath = System.getProperty("catalina.home");
            File dir = new File(rootPath + File.separator + "tmpFiles");
            if (!dir.exists())
                dir.mkdirs();

            // Create the file on server
            File serverFile = new File(dir.getAbsolutePath() + File.separator +name );
            BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(serverFile));
            stream.write(bytes);
            stream.close();

            return "You successfully uploaded file=" + name;
        } catch (Exception e) {
            return "You failed to upload " + name + " => " + e.getMessage();
        }
    } else {
        return "You failed to upload  because the file was empty.";
    }
}
File[]listOfFiles=folder.listFiles(); for(int i=0;i
您自己试过吗?如果是这样的话,你能给我们看一些你是如何做到这一点的代码吗?我已经分享了我使用的代码。这些代码没有显示任何实际列出文件的尝试,这是你的上传代码。是的,但我想知道我如何做到这一点,以及何时选择任何文档,它应该在jsp iframe中显示。所以您自己甚至没有尝试过研究这个问题,您只是决定立即询问答案?它显示在控制台上,但如果我想在网页中显示?谢谢。使用ajax调用servlet,并在响应中将文件列表作为json对象写入,并在ajax成功时获得它。参考这些链接,你会得到一个想法和
File folder = new File("path/to/your/uploaded/files/directory");
File[] listOfFiles = folder.listFiles();

    for (int i = 0; i < listOfFiles.length; i++) {
      if (listOfFiles[i].isFile()) {
        System.out.println("File " + listOfFiles[i].getName());
      } else if (listOfFiles[i].isDirectory()) {
        System.out.println("Directory " + listOfFiles[i].getName());
      }
    }