【问题标题】:How to send file names of Multipart file as list to front end page from controller如何将 Multipart 文件的文件名作为列表从控制器发送到前端页面
【发布时间】:2020-08-25 15:16:41
【问题描述】:

我正在尝试将文件从上传按钮上传到服务器中的临时文件夹,上传完成后,我想看到“成功”消息和上传的文件名列表。如果用户单击 UI 中的删除按钮,我想删除通过在请求中传递文件名来选择文件。请帮助我。下面是我编写的代码。

@ResponseBody
@JsonIgnore
@RequestMapping(value = "/uploadAttachment", method = RequestMethod.POST, produces = "text/html")
public List<String> uploadAttachment(final MultipartHttpServletRequest request)
{
    final List<String> fileNames = new ArrayList<String>();
    try
    {
        final List<MultipartFile> files = request.getFiles("files[]");
        final String orderPath = dPUploadOrderAttachmentFacade.createFolderForAttachment();
        LOG.info(orderPath);
        for (final MultipartFile file : files)
        {
            if (file.getSize() <=300000) {
            dPUploadOrderAttachmentFacade.storeTempFiles(file.getOriginalFilename(), file.getInputStream(), orderPath);
            final String fileName = file.getOriginalFilename();
            LOG.info(fileName);
            fileNames.add(fileName);
        }
        }
        LOG.info(fileNames);
        return fileNames;

    }
    catch (final Exception ex)
    {
        LOG.error(fileNames+"File Upload Failed due to " );
    }
    return fileNames;

}

【问题讨论】:

标签: java spring hybris


【解决方案1】:

添加代码 request.setAttribute("文件名", 文件名);

JSP

 <c:forEach var = "filename" items = ${filenames}>
    ${filename}
  </c:forEach>

试试这个

【讨论】:

    猜你喜欢
    • 2018-04-01
    • 2011-06-15
    • 2021-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-14
    • 1970-01-01
    • 2019-01-11
    相关资源
    最近更新 更多