从Content

编程入门 行业动态 更新时间:2024-10-11 07:30:42
本文介绍了从Content-Disposition获取文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用JSP将blob文件从HTML表单上传到MySQL数据库。我需要将文件名插入DB。我知道文件名存储在Content-Disposition标题中,我怎么能得到它?提前致谢!

I'm uploading a blob file from HTML form to MySQL database using JSP. I need to insert the filename into DB. I know that the filename is stored in the Content-Disposition header, how could I get that? Thanks in advance!

推荐答案

如果您使用带有 HttpServletRequest.getPart :

Part part = request.getPart("xxx"); // input type=file name=xxx String disposition = part.getHeader("Content-Disposition"); String fileName = disposition.replaceFirst("(?i)^.*filename=\"?([^\"]+)\"?.*$", "$1");

参见部分。

As @ Marc提到我没有处理URL编码。(他还使文件名周围的引号可选。)

As @Marc mentioned I did not treat URL encoding. (He also made the quotes around the filename optional.)

fileName = URLDecoder.decode(fileName, StandardCharsets.ISO_8859_1);

未选中,但标头的HTTP编码应为默认ISO -8859-1。

Not checked, but HTTP encoding for headers should be the default ISO-8859-1.

更多推荐

从Content

本文发布于:2023-10-10 09:27:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1478297.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Content

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!