web响应不同类型的文件

java 复制代码
    @GetMapping("/show")
    public void show(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String filename = request.getParameter("filename");
        String mimeType = request.getServletContext().getMimeType(filename);
        File file = new File("E:/" + filename);
        response.setContentType(mimeType);
        FileInputStream fileInputStream = new FileInputStream(file);
        ServletOutputStream outputStream = response.getOutputStream();
        int len = 0;
        byte[] bytes = new byte[8 * 1024];
        while ((len = fileInputStream.read(bytes)) != -1) {
            outputStream.write(bytes, 0, len);
        }
        fileInputStream.close();
        outputStream.close();
    }
相关推荐
袁哥大话安全3 天前
巡隐WEBSHELL扫描软件
人工智能·安全·web
佳心于琪5 天前
CTFshow——phpCVE
web·ctfshow·phpcve
传奇开心果编程7 天前
【Compose Multiplatform 跨端开发学与练】第8课 资源管理与主题
android·windows·学习·ios·kotlin·web·composer
传奇开心果编程7 天前
【Compose Multiplatform 跨端开发学与练】第9课 测试与调试
android·学习·macos·ios·kotlin·web·composer
hengdonghui7 天前
Writeup 4 红帽杯 2021 WebsiteManger
web·ctf·ssrf·sql布尔盲注
Seraphina369 天前
DVWA(SQL注入-low,medium,XSS反射-low)
前端·数据库·笔记·sql·网络安全·web·xss
hengdonghui9 天前
Writeup 4 津门杯 2021 Web hate_php
php·web·ctf·通配符
kali-Myon9 天前
ARTEX:AI 驱动的自动化漏洞挖掘平台
人工智能·安全·ai·自动化·web
hengdonghui9 天前
Writeup 4 红帽杯 2021 Web Find_It
web·ctf·备份文件泄露
熊猫钓鱼>_>11 天前
MetaAI深度研究研究报告
ai·meta·大模型·llm·agent·web·metaai