如何将Multipart文件的文件名作为列表从控制器发送到前端页面



我正试图将文件从上传按钮上传到服务器中的临时文件夹,上传完成后,我想看到"成功的";消息和上传的文件名列表。如果用户在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;
}

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

JSP

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

试试这个

最新更新