Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To start, it is firing a <code>GET</code> request, but the servlet is listening on <code>POST</code> requests only. You need to do this task in the <code>doGet()</code> method rather than <code>doPost()</code>.</p> <p>You also need to instruct the webbrowser what information exactly you're sending. This is to be done with the HTTP <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17" rel="nofollow noreferrer"><code>Content-Type</code></a> header. You can find <a href="http://www.iana.org/assignments/media-types" rel="nofollow noreferrer">here</a> an overview of the most used content types (mime types). You can use <a href="http://docs.oracle.com/javaee/5/api/javax/servlet/ServletResponse.html#setContentType%28java.lang.String%29" rel="nofollow noreferrer"><code>HttpServletResponse#setContentType()</code></a> to set it. In case of Quicktime <code>.mov</code> files, the content type ought to be <code>video/quicktime</code>.</p> <pre><code>response.setContentType("video/quicktime"); </code></pre> <p>Further, every media format has its own way of being embedded using the <code>&lt;embed&gt;</code> and/or the <code>&lt;object&gt;</code> element. You need to consult the documentation of the media format vendor for details how to use it. In case of Quicktime <code>.mov</code> files, you need to consult <a href="https://developer.apple.com/library/mac/#documentation/QuickTime/Conceptual/QTScripting_HTML/QTScripting_HTML_Document/ScriptingHTML.html" rel="nofollow noreferrer">Apple</a>. Carefully read this document. It is well written and it handles crossbrowser inconsitenties as well. You would likely prefer to <a href="https://developer.apple.com/library/mac/#documentation/QuickTime/Conceptual/QTScripting_HTML/QTScripting_HTML_Document/ScriptingHTML.html" rel="nofollow noreferrer"><em>Do It the Easy Way</em></a> with help of a simple JavaScript to bridge crossbrowser inconsitenties transparently.</p> <pre class="lang-html prettyprint-override"><code>&lt;script src="AC_QuickTime.js" language="javascript"&gt; &lt;/script&gt; &lt;script language="javascript"&gt; QT_WriteOBJECT('movies/filename.mov' , '320', '240' , ''); &lt;/script&gt; </code></pre> <hr> <p>That said, the posted servlet code is honestly said terrible written. Apart from the <code>doPost()</code> incorrectly been used, the IO resource handling is incorrect, every line has its own try/catch, exceptions are been suppressed and poor information is written to stdout, <code>InputStream#available()</code> is been misunderstood, the <code>DataOutputStream</code> is been used for no clear reason, the <code>InputStream</code> is never been closed, etcetera. No, that is certainly not the way. Please consult the <a href="http://docs.oracle.com/javase/tutorial/essential/io/" rel="nofollow noreferrer">basic Java IO</a> and <a href="http://docs.oracle.com/javase/tutorial/essential/exceptions/index.html" rel="nofollow noreferrer">basic Java Exception</a> tutorials to learn more about using them properly. Here's a slight rewrite how the servlet ought to look like:</p> <pre><code>protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String filename = URLDecoder.decode(request.getPathInfo(), "UTF-8"); File file = new File("/path/to/all/movies", filename); response.setHeader("Content-Type", "video/quicktime"); response.setHeader("Content-Length", file.length()); response.setHeader("Content-Disposition", "inline; filename=\"" + file.getName() + "\""); BufferedInputStream input = null; BufferedOutputStream output = null; try { input = new BufferedInputStream(new FileInputStream(file)); output = new BufferedOutputStream(response.getOutputStream()); byte[] buffer = new byte[8192]; for (int length = 0; (length = input.read(buffer)) &gt; 0;) { output.write(buffer, 0, length); } } finally { if (output != null) try { output.close(); } catch (IOException logOrIgnore) {} if (input != null) try { input.close(); } catch (IOException logOrIgnore) {} } } </code></pre> <p>Map it in <code>web.xml</code> as follows:</p> <pre class="lang-xml prettyprint-override"><code>&lt;servlet&gt; &lt;servlet-name&gt;movieServlet&lt;/servlet-name&gt; &lt;servlet-class&gt;com.example.MovieServlet&lt;/servlet-class&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;movieServlet&lt;/servlet-name&gt; &lt;url-pattern&gt;/movies/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; </code></pre> <p>The aforeposted JavaScript example shows exactly how you should use it. Just use path <code>/movies</code> and append the filename thereafter like so <code>/movies/filename.mov</code>. The <code>request.getPathInfo()</code> will return <code>/filename.mov</code>.</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.
 

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