0

我已按照将文件上传到服务器。该文件正在上传,但在上传文件后,它给出的页面名称为 filename.extension.jsp 并给出HTTP Status 404了屏幕截图: 上传文件后

但我只想向用户显示状态消息说File is uploaded. how to do this?

这是我的弹簧控制器方法:

@RequestMapping(value = "/CIMtrek_Compliance_Daily_Shipments_FileUpload", method = RequestMethod.POST)
    public String createComments(
            @RequestParam("CIMtrek_daily_originator_comments") MultipartFile uploadItem,
            HttpServletRequest request) {
        String uploadedFileName = "";
        try {
            String fileName = null;
            InputStream inputStream = null;
            OutputStream outputStream = null;
            if (uploadItem.getSize() > 0) {
                inputStream = uploadItem.getInputStream();
                fileName = request.getRealPath("") + "/resources/Attachment/"+uploadItem.getOriginalFilename();
                outputStream = new FileOutputStream(fileName);
                int readBytes = 0;
                byte[] buffer = new byte[10000];
                while ((readBytes = inputStream.read(buffer, 0, 10000)) != -1) {
                    outputStream.write(buffer, 0, readBytes);
                }
                outputStream.close();
                inputStream.close();
            }
            uploadedFileName = uploadItem.getOriginalFilename();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return uploadedFileName;
    }

请帮我找,

最好的祝福

4

1 回答 1

1

嗨@Anto,你可以这样做,

@RequestMapping(value = "/CIMtrek_Compliance_Daily_Shipments_FileUpload", method = RequestMethod.POST)
public String createComments(
        @RequestParam("CIMtrek_daily_originator_comments") MultipartFile uploadItem,
        HttpServletRequest request, ModelMap map) {
    String uploadedFileName = "";

     ...

        uploadedFileName = uploadItem.getOriginalFilename();
        // ---------------------------------------------------------------------------
        if("" != uploadedFileName || null != uploadedFileName) {
            map.put("message", new String("File is uploaded."));
        } else {
            map.put("message", new String("File is not uploaded."));
        }
        // ---------------------------------------------------------------------------

    } catch (Exception e) {
        e.printStackTrace();
    }
    return uploadedFileName;
}

还有你放的JSP

<c:out value="${message}"></c:out>

我希望能帮助你:)

于 2013-01-31T06:53:33.530 回答