When the jsp page image request is successful, the request path is treated as the jsp page address.

problem description

the picture request is successful, and the picture is displayed normally, but an error is reported in the background.

Page picture request

    @RequestMapping("/see/{id}")
    public void seeUrl(@PathVariable("id")Integer id) {
        sysFileService.fileDownload(id, false, true, response);
    }
    
    @Override
    public void fileDownload(Integer id, Boolean isName, Boolean isOpen, HttpServletResponse response) {
        TbFile tbFile = tbFileMapper.selectByPrimaryKey(id);
        if( null != tbFile) {
            File file = new File(tbFile.getSaveDir() + "/" + tbFile.getSaveName() + "." + tbFile.getFileSuffix());
            if(file.exists()){
                try {
                    FileUtils.fileDownload(file, tbFile, response, isName, isOpen);
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }
    
    public static void fileDownload(File file, TbFile tbFile, HttpServletResponse response, Boolean isName, Boolean isOpen) throws FileNotFoundException, IOException {

        String fullName = "";
        //
        if(null == isName) {
            fullName = new String(tbFile.getFileName().getBytes(),"ISO-8859-1") + "."+tbFile.getFileSuffix();
        } else {
            fullName = new String(tbFile.getSaveName().getBytes(),"ISO-8859-1") + "."+tbFile.getFileSuffix();
        }
        //
        if(null == isOpen) {
            //
            response.setContentType("application/force-download");
            response.setHeader("Content-Disposition", "attachment;fileName=" + fullName);
        }else {
            //
            response.setContentType(tbFile.getFileType());
            response.setHeader("Content-Disposition", "inline;fileName=" + fullName);
        }

        streamWrite(new FileInputStream(file), response.getOutputStream());

        logger.info(
                "fileDownload---" +
                    "\t:" + tbFile.getFileName() +
                    "\t:" + tbFile.getFileType() +
                    "\t:" + tbFile.getFileSize() +
                    "\t:" + tbFile.getSaveDir() +
                    "\t:" + tbFile.getSaveName()
        );
    }
    
    public static void streamWrite(InputStream is, OutputStream os) throws IOException {
        byte[] b = new byte[1024];
        int len;
        while((len = is.read(b)) != -1) {
            os.write(b, 0, len);
        }
        os.flush();
        os.close();
        is.close();
    }

what result do you expect? What is the error message actually seen?

1. Does this request path still need to be configured not to access the jsp file
2. When it is still backend response, set a value and do not request again after success.

May.31,2021

cause of the problem
I forgot to post the controller header information when describing the problem;

    @Autowired
    private HttpServletResponse response; 

because I injected response, into the request layer and used this to return the file request object, resulting in an error;
modified to

    @RequestMapping("/see/{id}")
    public void seeUrl(@PathVariable("id")Integer id, HttpServletResponse httpServletResponse) {
        sysFileService.fileDownload(id, false, true, httpServletResponse);
    }

reference link

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2bc7d-2baca.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2bc7d-2baca.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?