Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用struts2在jsp中播放多个视频_Jsp_Video_Struts2 - Fatal编程技术网

如何使用struts2在jsp中播放多个视频

如何使用struts2在jsp中播放多个视频,jsp,video,struts2,Jsp,Video,Struts2,大家好,我曾尝试在jsp页面中播放视频,并获得成功。如何在jsp中播放多个视频,视频文件在特定的folderFile系统中 下面是显示一个视频文件的代码 Jsp 我像这样更改了jsp struts.xml 动作类 如果要播放多个视频,则需要多个流 由于操作的流结果表示一个流,因此需要多个操作 例如,您可以对不同的操作进行许多AJAX调用,或者对同一个操作传递要作为参数播放的文件名。。。但我不明白为什么你要同时播放多个视频。我们有两只眼睛和一个大脑,真的擅长多任务处理,所以。。。问题还不清楚。我也

大家好,我曾尝试在jsp页面中播放视频,并获得成功。如何在jsp中播放多个视频,视频文件在特定的folderFile系统中 下面是显示一个视频文件的代码

Jsp

我像这样更改了jsp

struts.xml

动作类


如果要播放多个视频,则需要多个流

由于操作的流结果表示一个流,因此需要多个操作


例如,您可以对不同的操作进行许多AJAX调用,或者对同一个操作传递要作为参数播放的文件名。。。但我不明白为什么你要同时播放多个视频。我们有两只眼睛和一个大脑,真的擅长多任务处理,所以。。。问题还不清楚。

我也知道我有两只眼睛和一个大脑,问题是我不想一次播放所有视频,我只想在jsp中一次显示多个视频,这样用户就可以从jspWell的多个视频中选择任何一个,有很多方法可以做到这一点,这实在太广泛了。他们应该开始缓存吗?当它们停止时,您会显示缩略图还是实际的视频?这是一个很大的话题,有很多关于如何做到这一点的个人意见。顺便说一句,你仍然可以使用AJAX,你不能只用一个动作就完成它。我是AJAX新手,你能告诉我怎么做吗$.AJAX{type:'POST',url:'getFiles',dataType:'JSON',success:functiondata,success{$.eachdata,functionindex,value{var newRow=;$vid appendnewRow;};};};};
<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.xml**

<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;
        }
}
<html>
<body>
<form action="getFiles">
<input type="submit" value="check">
</form>
<s:iterator value="filesList">
     <video width="400" controls>    
      <source src="<s:url value='getFiles.action?fileName='/><s:property/>" type="video/mp4" />     
      <source src="mov_bbb.ogg" type="video/ogg"> Your browser does not support HTML5 video. </video> 
</s:iterator>
</body>
</html>
<struts>
    <package name="user" namespace="/" extends="struts-default">

    <action name="getFiles" class="com.pradeep.videostream.VideoStreamingAction">   
    <result name="success">index.jsp</result>   
    </action>

        <!-- <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 static final long serialVersionUID = 1L;
    private InputStream inputStream;
    private String yourContentType;
    private File[] filesArray = null;
    private List<String> filesList = new ArrayList<String>();

//getters and setters

    public String execute() throws Exception {


        File folder = new File("D://svn videos");
        filesArray = folder.listFiles();
        for (int i = 0; i < filesArray.length; i++) {
            String fileName=filesArray[i].getName();
            filesList.add(fileName);
        }

        HttpServletResponse response = ServletActionContext.getResponse();
        HttpServletRequest request = ServletActionContext.getRequest();
        String fileName = request.getParameter("fileName");
        System.out.println("GGGGGGGGGGGGGGGGG "+fileName);

         File file = new File(fileName); 
        setInputStream(new ByteArrayInputStream(FileUtils.readFileToByteArray(file)));
        return SUCCESS;
    }
}