当从控制器向jsp发送文件名时,如何在java脚本中从控制器向jsp页面获取文件名,它提供对象而不是文件名

时间:2019-06-25 13:14:44

标签: javascript java ajax spring model-view-controller

在JavaScript中将文件名从控制器发送到jsp时,它提供对象而不是文件名。当我对对象进行字符串化时,它将提供文件字节而不是文件名。如何在JavaScript中从控制器到jsp页面获取文件名?

// This is controller
@RequestMapping(value = "/downloadAttachment", method = RequestMethod.POST)
public @ResponseBody <AjaxResponseBody> AjaxResponseBody downloadAttachment(HttpServletRequest request, HttpServletResponse res, @ModelAttribute resolution resolution, Model model) throws SQLException, ClassNotFoundException, IOException {
    String fileName= file.getName();  // name of the file
    System.out.println(fileName);
    model.addAttribute("fileName",fileName);
    return (AjaxResponseBody) bytesArray;
}

JavaScript

<script>
    var fileName= $('fileName');
    console.log("fileName is ", fileName);
    console.log( "stringify attachment Name",JSON.stringify( fileName ) );
</script>

0 个答案:

没有答案