Note that there are some explanatory texts on larger screens.

plurals
  1. POFirefox cuts files, whose name contains spaces, in a Struts application
    primarykey
    data
    text
    <p>I am using the next class (simplified for the sake of understandability) to download images in a struts web application. It is working fine in every browser but firefox, which cuts names containing spaces. That it is to say: <strong>file with spaces.pdf</strong> gets downloaded in firefox as: <strong>file</strong> while in chrome, IE7 IE6 is downloaded as <strong>file with spaces.pdf</strong>.</p> <pre><code>public class Download extends Action { private static final int BUFFER_SIZE = 4096; public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String filename = "file with spaces.pdf"; File file = ... // variable containing the file; response.setStatus(HttpServletResponse.SC_OK); response.setContentType(getMimeType(request, file)); response.setHeader("Content-Type", getMimeType(request, file)); response.setHeader("Content-Disposition","attachment; filename="+ filename); InputStream is = new FileInputStream(file); sendFile(is, response); return null; } protected String getMimeType(HttpServletRequest request, File file) { ServletContext application = super.servlet.getServletContext(); return application.getMimeType(file.getName()); } protected void sendFile(InputStream is, HttpServletResponse response) throws IOException { BufferedInputStream in = null; try { int count; byte[] buffer = new byte[BUFFER_SIZE]; in = new BufferedInputStream(is); ServletOutputStream out = response.getOutputStream(); while(-1 != (count = in.read(buffer))) out.write(buffer, 0, count); out.flush(); } catch (IOException ioe) { System.err.println("IOException in Download::sendFile"); ioe.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } } } } </code></pre> <p>Does anyone know about what is going on here? Note i am using firefox 3.0.3 under Windows Vista. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload