使用视频标签和servlet显示视频

时间:2018-01-05 14:11:24

标签: java html5 jsf servlets video

我在我的.xhtml页面中使用html 5视频标签和java bean以及servlet显示视频,因为我的视频文件位于我的服务器上

  <video controls="controls" style="margin-top: 60px;width: 70%;height: 80vh">
                    <source src="/SPortal/VideoReader" type="video/mp4" />
                </video>

我的豆子:

    @PostConstruct
public void prepeareMethod() {
    //check the type of learning object
    try {
        LearningObject lo = dao.getLearningObjByID(reqId);

        String learnObjType = lo.getLearningObjTyId().getLearningObjectType();
        initialFile = new File(lo.getDirPath() + "\\" + lo.getFileName());
        InputStream targetStream = new FileInputStream(initialFile);

        FacesContext facesContext = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(false);

        session.setAttribute("loBytesArray", IOUtils.toByteArray(targetStream));

    } catch (Exception e) {
        e.printStackTrace();
    }

}

我的servlet:

 @Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    byte[] pdfBytesArray = (byte[]) request.getSession().getAttribute("loBytesArray");
    request.getSession().removeAttribute("loBytesArray");
    response.setContentType("video/mp4");
    response.setContentLength(pdfBytesArray.length);
    response.getOutputStream().write(pdfBytesArray);
}

问题是我在我的servlet上得到了这个错误,特别是在响应输出流的写入部分:

Warning: Setting non-serializable attribute value into ViewMap: (key: lessonLearnBN, value class: com.beans.LessonLearnBN) Warning: StandardWrapperValve[VideoReader]: Servlet.service() for servlet VideoReader threw exception java.io.IOException: Connection closed Caused by: java.io.IOException: An established connection was aborted by the software in your host machine Severe: Error Rendering View[/Error.xhtml] java.lang.IllegalStateException: getOutputStream() has already been called for this response

任何想法是什么问题??

0 个答案:

没有答案