在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>