GWT上传报错FileNotFoundException

GWT upload error FileNotFoundException

我在服务器上上传文件是这样的:我在服务器上创建文件夹,然后将所有上传文件放在这个文件夹中

@Override
    public String executeAction(HttpServletRequest request,
            List<FileItem> sessionFiles) throws UploadActionException {
        String response = "";
        int cont = 0;
        userNumber = request.getParameter("userNumber");
        File f = new File(ConfAppServer.getRealContextPath() + "/edoc/"
                + userNumber);
        for (FileItem item : sessionFiles) {
            if (false == item.isFormField()) {
                cont++;
                try {
                    String extension = item.getName().substring(
                            item.getName().length() - 3);
                    File file = null;
                    file = new File(ConfAppServer.getRealContextPath()
                            + "/edoc/"
                            + userNumber
                            + System.getProperty("file.separator")
                            + item.getName().substring(0,
                                    item.getName().length() - 4) + "."
                            + extension);
                    item.write(file);

                    receivedFiles.put(item.getFieldName(), file);
                    receivedContentTypes.put(item.getFieldName(),
                            item.getContentType());

                    response += "<file-" + cont + "-field>"
                            + item.getFieldName() + "</file-" + cont
                            + "-field>\n";
                    response += "<file-" + cont + "-name>" + item.getName()
                            + "</file-" + cont + "-name>\n";
                    response += "<file-" + cont + "-size>" + item.getSize()
                            + "</file-" + cont + "-size>\n";
                    response += "<file-" + cont + "-type>"
                            + item.getContentType() + "</file-" + cont
                            + "type>\n";
                } catch (Exception e) {
                    throw new UploadActionException(e);
                }
            }
        }
        removeSessionFileItems(request);
        return "<response>\n" + response + "</response>\n";
    }

它在我同事的电脑上运行良好,但在我的电脑上出现错误

文件名有误。请帮助我解决我的问题。谢谢

如您所见,文件名显示不正确。所以问题是Request/Response的编码问题。您需要添加一个过滤器 servlet。这里有一个tutorial.