Search code examples
servletshttprequestcontent-disposition

Servlet getSubmittedFileName removes slashes from path


I use an input element of type file to upload a file via an html form.

If the file is uploaded on Internet Explorer, the path is included in the file name.

Getting the file name as follows:

Collection<Part> parts = request.getParts();
for (Part part: parts) {
  if (part.getName().equals(inputName)) {
    System.out.println(part.getSubmittedFileName());
  }
}

Leads to the file's file name (in this case the full path because it was uploaded via ie) being displayed without slashes (eg: if the path were c://directory/file_name then it's printed as c:directoryfile_name)

If I get the header myself with part.getHeader("Content-Disposition") then I see that the slashes are present.

What is happening? How can I fix it so that the slashes are in getSubmittedFileName()?

Thanks


Solution

  • This appears to be a bug with Internet Explorer:

    Moreover, internet explorer's default settings for local (intranet) sites sends the entire path while the default behavior for internet sites is to not show the entire path. Therefore this is only an issue for local (intranet) uses, which for me is irrelevant.