gpt4 book ai didi

java - MultipartConfig 中的文件类型检查错误

转载 作者:行者123 更新时间:2023-12-02 04:29:10 25 4
gpt4 key购买 nike

正在开发上传图像的代码。但这不能正常工作。在我的 servlet 中,我将检查 contenttype 是否 contexttype"image/jpeg""image 匹配/jpeg" 文件将写入,否则显示错误消息

 Part filePart = request.getPart("pho`to");
String str = filePart.getContentType();

if (str != "image/jpeg" && str != "image/jpg") {
response.sendRedirect("uploadimage?action=errorinfiletype");
return;
}

User.updateImage(inputStream, uid);
response.sendRedirect("uploadimage?action=changed");

但是上面的代码总是显示错误信息。我认为我的 if 条件有错误。有人请帮忙

最佳答案

您可以执行以下操作:

if (str==null || !str.matches("image/jp(e)?g") ) {
response.sendRedirect("uploadimage?action=errorinfiletype");
return;
}

关于java - MultipartConfig 中的文件类型检查错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31722511/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com