Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Honestly, this approach is absolutely not right. </p> <ul> <li><p>You are sniffing the user agent in the server side and depending the business job on it. This is in all cases a bad idea. If all you want is to specify a different file depending on the user agent, then rather do it in the HTML side, with help of JavaScript or CSS. Both client side languages are able to identify the <em>real</em> browser without the need to sniff the user agent string (which is namely spoofable).</p></li> <li><p>You are not responding correctly on <code>Range</code> requests. You're sending the complete file back instead of the requested <code>Range</code>. Firefox and IE do not use range requests and that's why it "works". Chrome and Safari use range requests.</p></li> </ul> <p>This should be possible without sniffing the user agent and properly responding to <code>Range</code> requests by <code>RandomAccessFile</code> instead of <code>File</code> and <code>byte[]</code>. It's only pretty a lot of code to take all <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html">HTTP specification</a> requirements into account, so here's just a link where you can find a concrete example of such a servlet: <a href="http://balusc.blogspot.com/2009/02/fileservlet-supporting-resume-and.html">FileServlet supporting resume and caching</a>.</p> <p>However, much better is to delegate the job to the servletcontainer's default servlet. If it's for example Tomcat, then all you need to do is to add the following line to <code>/conf/server.xml</code>:</p> <pre class="lang-xml prettyprint-override"><code>&lt;Context docBase="D:\media" path="/media" /&gt; </code></pre> <p>This way the desired media files are just available by <a href="http://localhost:8080/media/final.ogg">http://localhost:8080/media/final.ogg</a> and <a href="http://localhost:8080/media/final.mp4">http://localhost:8080/media/final.mp4</a> without the need to homegrow a servlet.</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. 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.
 

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