Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ignore the value sent by the browser. This is indeed dependent on the client platform, browser and configuration used.</p> <p>If you want full control over content types based on the file extension, then better determine it yourself using <a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContext.html#getMimeType%28java.lang.String%29" rel="nofollow noreferrer"><code>ServletContext#getMimeType()</code></a>. </p> <pre><code>String mimeType = servletContext.getMimeType(filename); </code></pre> <p>The default mime types are definied in the <code>web.xml</code> of the servletcontainer in question. In for example Tomcat, it's located in <code>/conf/web.xml</code>. You can extend/override it in the webapp's <code>/WEB-INF/web.xml</code> as follows:</p> <pre><code>&lt;mime-mapping&gt; &lt;extension&gt;xlsx&lt;/extension&gt; &lt;mime-type&gt;application/vnd.openxmlformats-officedocument.spreadsheetml.sheet&lt;/mime-type&gt; &lt;/mime-mapping&gt; </code></pre> <p>You can also determine the mime type based on the actual file content (because the file extension may not per se be accurate, it can be fooled by the client), but this is a lot of work. Consider using a 3rd party library to do all the work. I've found <a href="http://sourceforge.net/projects/jmimemagic/" rel="nofollow noreferrer">JMimeMagic</a> useful for this. You can use it as follows:</p> <pre><code>String mimeType = Magic.getMagicMatch(file, false).getMimeType(); </code></pre> <p>Note that it doesn't support <em>all</em> mimetypes as reliable. You can also consider a combination of both approaches. E.g. if the one returns null or <code>application/octet-stream</code>, use the other. Or if both returns a different but "valid" mimetype, prefer the one returned by JMimeMagic.</p> <p>Oh, I almost forgot to add, in JSF you can obtain the <code>ServletContext</code> as follows:</p> <pre><code>ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(); </code></pre> <p>Or if you happen to use JSF 2.x already, use <a href="http://docs.oracle.com/javaee/6/api/javax/faces/context/ExternalContext.html#getMimeType%28java.lang.String%29" rel="nofollow noreferrer"><code>ExternalContext#getMimeType()</code></a> instead.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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