如何使用struts2和jsp从系统位置播放视频

如何使用struts2和jsp从系统位置播放视频,jsp,video,struts2,Jsp,Video,Struts2,嗨,我正在努力使用struts2从系统位置播放jsp文件中的视频文件。但如果我将视频文件(Sample.mp4)放在eclipse中的web内容下,并在jsp中使用文件名如下的视频标记,它就会播放 <source src="Sample.mp4" type="video/mp4"/> struts.xml <action name="download" class="com.sample.actions.DownloadAction"> <result na

嗨,我正在努力使用struts2从系统位置播放jsp文件中的视频文件。但如果我将视频文件(Sample.mp4)放在eclipse中的web内容下,并在jsp中使用文件名如下的视频标记,它就会播放

<source src="Sample.mp4" type="video/mp4"/>
struts.xml

<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>

${contentType}
文件输入流
附件filename=“${filename}”
1024
Jsp中的

<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>

这是一个用于视频显示的jsp页面

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
 <video width="400" controls>
 <source src="<s:url value="videoStream" />" type="video/mp4"/>
  <source src="mov_bbb.ogg" type="video/ogg">
  Your browser does not support HTML5 video.
</video>
</body>
</html>

下面是一个用于视频显示的jsp页面

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
 <video width="400" controls>
 <source src="<s:url value="videoStream" />" type="video/mp4"/>
  <source src="mov_bbb.ogg" type="video/ogg">
  Your browser does not support HTML5 video.
</video>
</body>
</html>
<struts>
    <package name="user" namespace="/" extends="struts-default">
        <action name="videoStream" class="com.pradeep.videostream.VideoStreamingAction">
            <result name="success" type="stream">
                <param name="contentType">${yourContentType}</param>
                <param name="inputName">inputStream</param>
                <param name="contentDisposition">attachment;filename="${yourFileName}"</param>
                <param name="bufferSize">1024</param>
            </result>
        </action>
    </package>
</struts>
public class VideoStreamingAction extends ActionSupport {
    private InputStream inputStream;
     private String yourContentType;

        // getters and setters 

 public String execute() throws Exception {
           yourContentType = "video/mp4";
           File file =new File("D://svn videos//Create Java Spring Web MVC Project With Maven [EDITED].mp4");
           setInputStream(new ByteArrayInputStream(FileUtils.readFileToByteArray(file)));   
           return SUCCESS;
        }
}