在SQL Server上传后无法显示视频

时间:2017-02-24 16:11:42

标签: java sql-server video-streaming

我想显示在SQL Server上上传的文件。 当文件是图像(jpg,gif,png,...)时我成功了 但是在SQL服务器上传视频后,我无法像this Screenshot看起来那样显示和播放。

贝娄是:

servlet DisplayThoughtFile.java



public class DisplayThoughtFile extends HttpServlet
{
    private static final long serialVersionUID = 4593558495041379082L;
    @Override
    public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException 
    {
        Statement stmt = null;
        ResultSet rs;
        InputStream sImage;
        try 
        {
            String id = request.getParameter("ThoughtFileId");
            Connection con = Database.getConnection();
            stmt = con.createStatement();
            String strSql = "select thoughtFilePath from thought where thoughtId='" + id + "' ";
            rs = stmt.executeQuery(strSql);
            if (rs.next())
            {
                byte[] bytearray = new byte[1048576];
                int size = 0;
                sImage = rs.getBinaryStream(1);
                response.reset();
                response.setContentType("video/quicktime");
                while ((size = sImage.read(bytearray)) != -1) 
                {
                    response.getOutputStream().write(bytearray, 0, size);
                }
            }
        } 
        catch (Exception e) 
        {
            e.printStackTrace();
        }
    }




页面 thought.xhtml



 <h:outputLink value="DisplayThoughtFile?ThoughtFileId=#{item.tId}" target="_blank" >
    <h:graphicImage value="DisplayThoughtFile?ThoughtFileId=#{item.tId}" width="50" height="50"/>
</h:outputLink>
&#13;
&#13;
&#13;

我添加到 web.xml

&#13;
&#13;
<servlet>
    <description></description>
    <display-name>DisplayThoughtFile</display-name>
    <servlet-name>DisplayThoughtFile</servlet-name>
    <servlet-class>com.esprit.chat.beans.DisplayThoughtFile</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>DisplayThoughtFile</servlet-name>
    <url-pattern>/DisplayThoughtFile</url-pattern>
</servlet-mapping>
&#13;
&#13;
&#13;

请你解决这个问题。非常感谢。

0 个答案:

没有答案