如何在struts2中使用数据库值进行视频流传输

时间:2017-05-02 11:39:23

标签: eclipse jsp video struts2

嗨,大家好我试图在jsp中播放视频,数据库值从系统本地驱动器获取视频但是如果我在网页内容下粘贴视频eclipse视频将播放如何解决此错误?

在eclipse中使用网络内容下的视频文件的代码

<video width="400" controls>
 <source src="Sample.mp4" type="video/mp4"/>
  <source src="mov_bbb.ogg" type="video/ogg">
  Your browser does not support HTML5 video.
</video>

尝试从系统本地驱动器中获取和播放

JSP

<html>
<body>

 <%
  String url = request.getScheme() + "://" + request.getServerName()
    + ":" + request.getServerPort() + request.getContextPath();
  url = url + "//download";
 %>
 <video width="320" height="240" controls>
  <source src=<%=url%>>
 </video>
</body>
</html>

动作类

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import com.opensymphony.xwork2.ActionSupport;

public class DownloadAction extends ActionSupport {

    private InputStream fileInputStream;
    private String fileToDownload = "/video/Sample.mp4";
    private String fileName;

    private String contentType = "video/mp4";

    public String getContentType() {
        return contentType;
    }

    public void setContentType(String contentType) {
        this.contentType = contentType;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public InputStream getFileInputStream() {
        fileName = "notes.docx";
        return fileInputStream;
    }

    public String execute() throws Exception {
        fileInputStream = new FileInputStream(new File(fileToDownload));
        return SUCCESS;
    }

    public String getFileName() {
        return fileName;
    }

}

struts xml

<struts>
 <package name="default" extends="struts-default">
  <action name="download" class="com.sample.actions.DownloadAction">
   <result name="success" type="stream">
    <param name="contentType">${contentType}</param>
    <param name="inputName">fileInputStream</param>
    <param name="contentDisposition">attachment;filename="${fileName}"</param>
    <param name="bufferSize">1024</param>
   </result>
  </action>
 </package>
</struts>

0 个答案:

没有答案